[embed] Shortcode in WordPress

The [embed] shortcode allows you to embed specified URLs with the desired width and height.

The WP_Embed::shortcode() method is responsible for processing this shortcode.

By default:

  • Width is equal to $GLOBALS['content_width'] or 500.
  • Height is equal to min( ceil( $width * 1.5 ), 1000 ) based on the width.

For more details, see wp_embed_defaults()

This shortcode is only processed after the the_content filter is first executed. If you need to execute this shortcode BEFORE or WITHOUT the WordPress Loop and you are not using the_content(), you need to call the following method and pass the content containing [embed]:

$GLOBALS['wp_embed']->run_shortcode( 'Content with [embed] shortcode' );

Usage

[embed width="123" height="456"]URL[/embed]

Parameters

$width(number)
The width of the iframe.
Default: $GLOBALS['content_width'] or 500
$height(number)
The height of the iframe.
Default: min( ceil( 1.5 $width ), 1000 )
$src(string)
URL when the shortcode is used non-content based.
Default: ''
$discover(true/false)
$attr['discover'] parameter for the wp_oembed_get( $url, $attr ) function.
Default: apply_filters( 'embed_oembed_discover', true )

Examples

#1 Embedding a YouTube video

[embed width="500" height="300"]https://youtu.be/SRWrQMwGYsQ[/embed]