Skip to content

Bundled Themes: Print the stylesheet LINK tag with wp_print_style_link_tag() when available - #14500

Draft
huubl wants to merge 3 commits into
WordPress:trunkfrom
huubl:huubl-style-link-themes
Draft

huubl wants to merge 3 commits into
WordPress:trunkfrom
huubl:huubl-style-link-themes

Conversation

@huubl

@huubl huubl commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

This depends on #14498, which introduces wp_get_style_link_tag() and wp_print_style_link_tag(). Until that lands, the diff here also includes the API. The diff of only this change is: huubl/wordpress-develop@huubl-style-link-api...huubl-style-link-themes

Twenty Ten and Twenty Eleven print the LINK tag for their stylesheet in header.php by hand. This prints it with wp_print_style_link_tag() when it exists, so that its attributes can be filtered with wp_style_attributes, for example to add a CSP nonce, falling back to printing the tag directly on older versions of WordPress, as #14217 does for STYLE tags.

The rendered markup of both themes is unchanged, byte for byte, with and without the API, including for a stylesheet URL with several query arguments.

Trac ticket: https://core.trac.wordpress.org/ticket/66342

Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot, Claude Code
Model(s): GPT-6 Luna, Claude Opus 5.5
Used for: The initial implementation and tests were written with GitHub Copilot. Claude Code was used under my direction for review, the backward compatibility fixes, splitting the change, and tests, and I reviewed the result.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@huubl
huubl force-pushed the huubl-style-link-themes branch from 244211c to a8f5e80 Compare October 19, 2026 18:05
Introduce `wp_get_style_link_tag()` and `wp_print_style_link_tag()`,
which build a `<link rel="stylesheet">` tag with `WP_HTML_Tag_Processor`,
and the `wp_style_attributes` filter, so that attributes such as a CSP
`nonce`, `integrity` or `crossorigin` can be added to stylesheet links
without editing HTML strings. This complements `wp_get_script_tag()` and
the `wp_script_attributes` filter, and `wp_get_inline_style_tag()` for
inline STYLE tags.

`WP_Styles::do_item()`, including right-to-left and alternate
stylesheets, the concatenated stylesheet printed by `_print_styles()`,
`wp_admin_css()` and `locale_stylesheet()` now print their LINK tags
with the API.

Backward compatibility:

- The `style_loader_tag` and `wp_admin_css` filters are kept, and the
  markup they are passed is unchanged: the values Core supplies are
  still escaped with `esc_attr()` or `esc_url()`, single-quoted and in
  the same order, since callbacks have long edited that markup as a
  string. Attributes added by the `wp_style_attributes` filter are
  printed after them.
- `style_loader_tag` is still passed the escaped URL from before the
  `wp_style_attributes` filter, and each URL is still escaped, and
  passed to the `clean_url` filter, once.
- In the markup passed to `style_loader_tag` and `wp_admin_css`, a
  quote returned by a filtered escaping function, such as a
  `clean_url` callback, is encoded, so it can no longer end an
  attribute value early. Like `wp_get_script_tag()`,
  `wp_get_style_link_tag()` prints the `href` as the Tag Processor
  escapes it.
- A supplied `id` cannot be changed or removed by the filter, since
  code locates LINK tags by it, such as the color scheme picker on the
  user profile screen with `colors-css`. A `_doing_it_wrong()` notice
  naming the function that printed the tag is issued if the filter
  tries.
- `WP_Styles::do_item()` no longer calls `WP_Styles::_css_href()`, so
  overriding that method in a subclass no longer changes the printed
  URL.
- The URL printed by `locale_stylesheet()` is now escaped.

Attributes are printed in the order they are given. An attribute that
the Tag Processor rejects, such as a URL with a disallowed protocol, is
left out rather than printed empty.

See #66342, #51325.
@huubl
huubl force-pushed the huubl-style-link-themes branch from a8f5e80 to 56efa38 Compare October 19, 2026 18:35
huubl added 2 commits October 20, 2026 18:15
Keep the new stylesheet link tag API, filter and backward compatibility tests, while retaining the Core removal of script and style concatenation (r64585). Drop the two tests for concatenated stylesheet output, which no longer exists.
…nk_tag()` when available.

Twenty Ten and Twenty Eleven print the LINK tag for their stylesheet in
header.php by hand. Print it with `wp_print_style_link_tag()` when it
exists, so that its attributes can be filtered with `wp_style_attributes`,
for example to add a CSP `nonce`, falling back to printing the tag
directly on older versions of WordPress. Both print the same markup as
before unless the filter changes it.

Follow-up to the style link tag API. See #66342, #51325.
@huubl
huubl force-pushed the huubl-style-link-themes branch from 56efa38 to aa247e0 Compare October 20, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant