wp_embed_defaults() WordPress Function

The wp_embed_defaults() function allows you to set the default width and height for your embedded content. This can be useful if you want to ensure that all of your embedded content is the same size.

wp_embed_defaults( string $url = '' ) #

Creates default array of embed parameters.


Description

The width defaults to the content width as specified by the theme. If the theme does not specify a content width, then 500px is used.

The default height is 1.5 times the width, or 1000px, whichever is smaller.

The ’embed_defaults’ filter can be used to adjust either of these values.


Top ↑

Parameters

$url

(string)(Optional) The URL that should be embedded.

Default value: ''


Top ↑

Return

(int[]) Indexed array of the embed width and height in pixels.

  • (int) The embed width.
  • '1'
    (int) The embed height.


Top ↑

Source

File: wp-includes/embed.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.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.