wp_embed_handler_youtube

函式
wp_embed_handler_youtube ( $matches, $attr, $url, $rawattr )
引數
  • (array) $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
    Required:
  • (array) $attr Embed attributes.
    Required:
  • (string) $url The original URL that was matched by the regex.
    Required:
  • (array) $rawattr The original unmodified attributes.
    Required:
返回值
  • (string) The embed HTML.
定義位置
相關方法
wp_embed_handler_videowp_embed_handler_audiowp_embed_handler_googlevideowp_oembed_register_routewp_embed_register_handler
引入
4.0.0
棄用
-

wp_embed_handler_youtube: 這個函式是一個回撥函式,用於處理WordPress中的YouTube視訊嵌入: 當使用者在一個文章或頁面中嵌入YouTube視訊時,這個函式被呼叫來處理嵌入程式碼。

YouTube iframe嵌入處理回撥。

捕捉那些不能被oEmbed解析的YouTube iframe嵌入的URL,但可以被翻譯成一個可以解析的URL。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
global $wp_embed;
$embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) );
/**
* Filters the YoutTube embed output.
*
* @since 4.0.0
*
* @see wp_embed_handler_youtube()
*
* @param string $embed YouTube embed output.
* @param array $attr An array of embed attributes.
* @param string $url The original URL that was matched by the regex.
* @param array $rawattr The original unmodified attributes.
*/
return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
}
function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) { global $wp_embed; $embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) ); /** * Filters the YoutTube embed output. * * @since 4.0.0 * * @see wp_embed_handler_youtube() * * @param string $embed YouTube embed output. * @param array $attr An array of embed attributes. * @param string $url The original URL that was matched by the regex. * @param array $rawattr The original unmodified attributes. */ return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr ); }
function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
	global $wp_embed;
	$embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) );

	/**
	 * Filters the YoutTube embed output.
	 *
	 * @since 4.0.0
	 *
	 * @see wp_embed_handler_youtube()
	 *
	 * @param string $embed   YouTube embed output.
	 * @param array  $attr    An array of embed attributes.
	 * @param string $url     The original URL that was matched by the regex.
	 * @param array  $rawattr The original unmodified attributes.
	 */
	return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
}

常見問題

FAQs
檢視更多 >