wp_embed_defaults

函式
wp_embed_defaults ( $url = '' )
引數
  • (string) $url Optional. The URL that should be embedded. Default empty.
    Required:
    Default: (empty)
返回值
  • (int[]) { Indexed array of the embed width and height in pixels. @type int $0 The embed width. @type int $1 The embed height. }
定義位置
相關方法
wp_oembed_getwp_get_widget_defaultswp_install_defaultswp_embed_handler_audiowp_filter_oembed_result
引入
2.9.0
棄用
-

wp_embed_defaults: 這個過濾器是用來修改WordPress oEmbed系統的預設選項的。oEmbed系統是用來將第三方網站的媒體嵌入到WordPress的文章和頁面中,這個過濾器可以用來定製oEmbed系統的行為。

建立預設的嵌入引數陣列。

寬度預設為主題所指定的內容寬度。如果主題沒有指定內容的寬度,那麼就使用500px。

預設高度是寬度的1.5倍,或1000px,以較小者為準。

{@see ’embed_defaults’}過濾器可以用來調整這些值中的任何一個。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_embed_defaults( $url = '' ) {
if ( ! empty( $GLOBALS['content_width'] ) ) {
$width = (int) $GLOBALS['content_width'];
}
if ( empty( $width ) ) {
$width = 500;
}
$height = min( ceil( $width * 1.5 ), 1000 );
/**
* Filters the default array of embed dimensions.
*
* @since 2.9.0
*
* @param int[] $size {
* Indexed array of the embed width and height in pixels.
*
* @type int $0 The embed width.
* @type int $1 The embed height.
* }
* @param string $url The URL that should be embedded.
*/
return apply_filters( 'embed_defaults', compact( 'width', 'height' ), $url );
}
function wp_embed_defaults( $url = '' ) { if ( ! empty( $GLOBALS['content_width'] ) ) { $width = (int) $GLOBALS['content_width']; } if ( empty( $width ) ) { $width = 500; } $height = min( ceil( $width * 1.5 ), 1000 ); /** * Filters the default array of embed dimensions. * * @since 2.9.0 * * @param int[] $size { * Indexed array of the embed width and height in pixels. * * @type int $0 The embed width. * @type int $1 The embed height. * } * @param string $url The URL that should be embedded. */ return apply_filters( 'embed_defaults', compact( 'width', 'height' ), $url ); }
function wp_embed_defaults( $url = '' ) {
	if ( ! empty( $GLOBALS['content_width'] ) ) {
		$width = (int) $GLOBALS['content_width'];
	}

	if ( empty( $width ) ) {
		$width = 500;
	}

	$height = min( ceil( $width * 1.5 ), 1000 );

	/**
	 * Filters the default array of embed dimensions.
	 *
	 * @since 2.9.0
	 *
	 * @param int[]  $size {
	 *     Indexed array of the embed width and height in pixels.
	 *
	 *     @type int $0 The embed width.
	 *     @type int $1 The embed height.
	 * }
	 * @param string $url  The URL that should be embedded.
	 */
	return apply_filters( 'embed_defaults', compact( 'width', 'height' ), $url );
}

常見問題

FAQs
檢視更多 >