[wp-trac] [WordPress Trac] #59886: enqueue scripts is html encoding the resulting string
WordPress Trac
noreply at wordpress.org
Sat Nov 11 00:17:34 UTC 2023
#59886: enqueue scripts is html encoding the resulting string
--------------------------+------------------------------
Reporter: probed | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.4
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+------------------------------
Comment (by dmsnell):
> `$url' async data-components='spektrix-login-status,spektrix-donate
,spektrix-merchandise,spektrix-memberships,spektrix-basket-summary
,spektrix-gift-vouchers`
@probed what are you trying to accomplish here? it looks like you're
attempting to add additional HTML attributes to the `SCRIPT` element by
breaking out of the URL. is that the case?
if that's the case, I might recommend using
[https://developer.wordpress.org/reference/hooks/script_loader_tag/ the
script_loader_tag filter] instead.
{{{#!php
<?php
add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
if ( 'webcomponents-spektrix' !== $handle ) {
return $tag;
}
$processor = new WP_HTML_Tag_Processor( $tag );
$processor->set_attribute( 'async', true );
$processor->set_attribute( 'data-components', 'spektrix-login-
status,spektrix-donate,spektrix-merchandise,spektrix-memberships,spektrix-
basket-summary,spektrix-gift-vouchers' );
return $processor->get_updated_html();
}, 10, 3 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59886#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list