wp_oembed_get()
Embeds the object by specified URL. Tries to get the HTML code from the passed URL by using supported WordPress oEmbed providers.
oEmbed — it is an open format designed to make it easier to embed content from one web page into another. Content can be a photo, video, link, or another type of data.
This function does not cache the result, use the WP_Embed object to cache it:
global $wp_embed; echo $wp_embed->autoembed('https://www.youtube.com/watch?v=c6afCBCzLAY&t=2s'); /* returns: <iframe width="600" height="338" src="https://www.youtube.com/embed/c6afCBCzLAY?start=2&feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> */
No Hooks.
Return
String|false
. The embed HTML on success, false on failure.
Usage
wp_oembed_get( $url, $args );
- $url(string) (required)
- The URL that should be embedded.
- $args(array|string)
Additional arguments for retrieving embed HTML.
Default: ''
-
width(int|string)
Optional. The maxwidth value passed to the provider URL. -
height(int|string)
Optional. The maxheight value passed to the provider URL. - discover(true|false)
Optional. Determines whether to attempt to discover link tags at the given URL for an oEmbed provider when the provider URL is not found in the built-in providers list.
Default: true
-
Examples
#1 Embedding with parameters
Embed YouTube video and specify it's width:
$embed_code = wp_oembed_get('http://www.youtube.com/watch?v=AbcDeFg123', array('width' => 400) );
Return:
<iframe width="400" height="225" src="http://www.youtube.com/embed/jr8ouxln3CE?feature=oembed" frameborder="0" allowfullscreen></iframe>
#2 Embed (Build-in) the URL of a supported oEmbed in WordPress
$embed_code = wp_oembed_get( 'http://www.youtube.com/watch?v=AbcDeFg123' );
Return:
<iframe width="500" height="281" src="https://www.youtube.com/embed/AbcDeFg123?feature=oembed" frameborder="0" allowfullscreen></iframe>
Note: if the video is not available, the URL will not be processed.
Notes
- See: WP_oEmbed
Changelog
Since 2.9.0 | Introduced. |
wp_oembed_get() wp oembed get code WP 6.7.2
function wp_oembed_get( $url, $args = '' ) { $oembed = _wp_oembed_get_object(); return $oembed->get_html( $url, $args ); }