Repository navigation
Strip <link rel="alternate"> from global header REST output - #734
Merged
Merged
Conversation
Remove feed_links, feed_links_extra, and wp_oembed_add_discovery_links from wp_head when rendering the global header via REST API. These <link rel="alternate"> tags are not relevant for the reusable header component served to other sites. Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Remove <link rel="alternate"> tags from Global Header output
Remove Mar 9, 2026
<link rel="alternate"> from global header REST endpoint output
…lobal header output Replace the remove_action approach (which only handled known core actions) with WP_HTML_Tag_Processor-based filtering that catches <link rel="alternate"> tags from any source, including plugins. Uses token-based rel attribute matching to avoid false positives with non-alternate rel values. Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copilot
AI
changed the title
Remove
Strip Mar 9, 2026
<link rel="alternate"> from global header REST endpoint output<link rel="alternate"> from global header REST output using WP_HTML_Tag_Processor
Replace the two-step WP_HTML_Tag_Processor + regex approach with a single regex that directly matches and removes <link> tags whose rel attribute contains the word "alternate". Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copilot
AI
changed the title
Strip
Strip Mar 9, 2026
<link rel="alternate"> from global header REST output using WP_HTML_Tag_Processor<link rel="alternate"> from global header REST output
dd32
marked this pull request as ready for review
March 9, 2026 05:13
Member
|
@copilot Can you add any tests for this? |
Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Contributor
Author
Added PHPUnit tests in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The global header REST endpoint includes
wp_head()output for styles, which also emits<link rel="alternate">tags (feed links, oEmbed discovery, hreflang from plugins, etc.) that are irrelevant when the header is embedded in other sites. The previous approach usedremove_actionon known core hooks, which missed tags added by plugins.remove_actioncalls (feed_links,feed_links_extra,wp_oembed_add_discovery_links) with a regex-based strip on the rendered$head_markup, catching all sourcesremove_head_alternate_links()— strips<link>tags whererelcontains thealternatetoken, applied only during REST requestsWord boundary (
\b) prevents false matches on values likerel="myalternate".phpunit/test-global-header-footer.php) covering removal of RSS/Atom feed links, oEmbed discovery, hreflang tags, single-quoted and non-self-closing variants, compoundrelvalues, preservation of non-alternate links (stylesheet, canonical, preconnect, icon), mixed markup, and edge cases.Original prompt
<link rel="alternate"in the headers #733🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.