[wp-trac] [WordPress Trac] #63806: Bundled themes: Scripts are printed directly without using wp_print_script_tag()/wp_print_inline_script_tag()
WordPress Trac
noreply at wordpress.org
Tue Sep 2 17:34:51 UTC 2025
#63806: Bundled themes: Scripts are printed directly without using
wp_print_script_tag()/wp_print_inline_script_tag()
---------------------------+-------------------------
Reporter: westonruter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.9
Component: Bundled Theme | Version: 5.7
Severity: normal | Resolution:
Keywords: has-patch | Focuses: javascript
---------------------------+-------------------------
Comment (by westonruter):
Replying to [comment:6 sabernhardt]:
> 2. Polyfills might need updating later, and I think any site that opts
in for a strict CSP should have a newer version of WordPress than 5.7.
Could the existing theme functions simply check if the
`wp_print_inline_script_tag` function exists and print/echo if not?
> {{{#!php
> /**
> * JavaScript Detection.
> *
> * Adds a `js` class to the root `<html>` element when JavaScript is
detected.
> *
> * @since Twenty Fifteen 1.1
> * @since Twenty Fifteen 4.1 Added `wp_print_inline_script_tag()`
support.
> */
> function twentyfifteen_javascript_detection() {
> $js = "(function(html){html.className = html.className.replace
(/\bno-js\b/,'js')})(document.documentElement);";
>
> if ( function_exists( 'wp_print_inline_script_tag' ) ) {
> wp_print_inline_script_tag( $js );
> } else {
> printf( "<script>%s</script>\n", $js );
> }
> }
> add_action( 'wp_head', 'twentyfifteen_javascript_detection', 0 );
> }}}
This is a good point. If the functions aren't available, then a site
wouldn't be able to opt-in to Strict CSP anyway since the other core code
wouldn't be using them. So yes, I think directly printing the scripts as
you suggest would make sense if the functions aren't available.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63806#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list