wp_maybe_enqueue_oembed_host_js() WordPress Function

The wp_maybe_enqueue_oembed_host_js() function is used to determine whether to enqueue the WordPress oEmbed JavaScript on the front-end. This includes the necessary JavaScript to handle any front-end oEmbed requests.

wp_maybe_enqueue_oembed_host_js( string $html ) #

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.


Top ↑

Parameters

$html

(string)(Required)Embed markup.


Top ↑

Return

(string) Embed markup (without modifications).


Top ↑

Source

File: wp-includes/embed.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.