On this page
wp_maybe_enqueue_oembed_host_js( string $html ): string
Enqueue the wp-embed script if the provided oEmbed HTML contains a post embed.
Description
In order to only enqueue the wp-embed script on pages that actually contain post embeds, this function checks if the provided HTML contains post embed markup and if so enqueues the script so that it will get printed in the footer.
Parameters
$htmlstring Required-
Embed markup.
Return
string Embed markup (without modifications).
Source
File: wp-includes/embed.php. View all references
function wp_maybe_enqueue_oembed_host_js( $html ) {
if (
has_action( 'wp_head', 'wp_oembed_add_host_js' )
&&
preg_match( '/<blockquote\s[^>]*?wp-embedded-content/', $html )
) {
wp_enqueue_script( 'wp-embed' );
}
return $html;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_enqueue_script() wp-includes/functions.wp-scripts.php | Enqueue a script. |
| has_action() wp-includes/plugin.php | Checks if any action has been registered for a hook. |
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_maybe_enqueue_oembed_host_js