[wp-trac] [WordPress Trac] #44632: Properly enqueue wp-embed
WordPress Trac
noreply at wordpress.org
Mon Apr 19 18:10:50 UTC 2021
#44632: Properly enqueue wp-embed
-------------------------+------------------------------
Reporter: alpipego | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Embeds | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+------------------------------
Changes (by ocean90):
* keywords: => has-patch
Comment:
We probably can't change how the script is enqueued since it would break
any usage of `remove_action( 'wp_head', 'wp_oembed_add_host_js' );`. But I
don't see any harm in setting the `in_footer` argument as done in
[attachment:"44632.diff"].
Possible workaround:
{{{#!php
<?php
/**
* Improves handling of `wp-embed` script enqueue.
*
* By default the script is enqueued on all pages, registered on `wp_head`
with
* priority 10. This prevents third-party plugins to handle this properly
which
* expect all scripts/styles to be registered on `wp_enqueue_scripts`,
also hooked
* into `wp_head` with priority 1.
*
* This function unregisters the default action and registers it via
`wp_enqueue_scripts`.
* It also makes sure to enqueue the script in the footer which it isn't
by default.
*
* @link https://core.trac.wordpress.org/ticket/44632
*/
function trac_44632_wp_embed(): void {
if ( ! has_action( 'wp_head', 'wp_oembed_add_host_js' ) ) {
return;
};
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
wp_scripts()->add_data( 'wp-embed', 'group', 1 );
add_action( 'wp_enqueue_scripts', 'wp_oembed_add_host_js' );
}
add_action( 'wp_head', 'trac_44632_wp_embed', 0 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44632#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list