wp_maybe_enqueue_oembed_host_js

函式
wp_maybe_enqueue_oembed_host_js ( $html )
引數
  • (string) $html Embed markup.
    Required:
返回值
  • (string) Embed markup (without modifications).
定義位置
相關方法
enqueue_embed_scriptswp_oembed_add_host_jswp_enqueue_stored_stylesenqueue_comment_hotkeys_jswp_maybe_load_embeds
引入
5.9.0
棄用
-

wp_maybe_enqueue_oembed_host_js: 這是一個函式,用於在必要時排隊等待oEmbed主機JavaScript檔案: 這個函式用於確保oEmbed內容的正常顯示。

如果提供的oEmbed HTML包含一個post embed,那麼就排隊等待wp-embed指令碼。

為了只在實際包含文章嵌入的頁面上排隊等候wp-embed指令碼,這個函式檢查所提供的HTML是否包含文章嵌入標記,如果是,就排隊等候指令碼,這樣它就會被列印在頁尾。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_maybe_enqueue_oembed_host_js( $html ) {
if (
has_action( 'wp_head', 'wp_oembed_add_host_js' )
&&
preg_match( '/<blockquotes[^>]*?wp-embedded-content/', $html )
) {
wp_enqueue_script( 'wp-embed' );
}
return $html;
}
function wp_maybe_enqueue_oembed_host_js( $html ) { if ( has_action( 'wp_head', 'wp_oembed_add_host_js' ) && preg_match( '/<blockquotes[^>]*?wp-embedded-content/', $html ) ) { wp_enqueue_script( 'wp-embed' ); } return $html; }
function wp_maybe_enqueue_oembed_host_js( $html ) {
	if (
		has_action( 'wp_head', 'wp_oembed_add_host_js' )
		&&
		preg_match( '/<blockquotes[^>]*?wp-embedded-content/', $html )
	) {
		wp_enqueue_script( 'wp-embed' );
	}
	return $html;
}

常見問題

FAQs
檢視更多 >