Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp oembed get


Takes a URL and Attempts to fetch the embed HTML for it using oEmbed.


 <?php $embed_code wp_oembed_get$url$args );   ?> 


(string) (required) The URL that should be embedded.
Default: None
(array) (optional) Addtional arguments and parameters.
Default: None

Available arguments:

  • height
  • width

NOTE: above it says "no default" but that relates to the $args variable passed in. Internally it retrieves some default values conditionally based on site settings.

If you do not pass in a width argument, then the function will check for a content_width setting, and a media settings max width. If neither of those are set, and you don't pass in your own width, the used width will be '500'. If one of those values is set, it'll use that set value.

If you do not pass in a height argument, then the function will check for a media settings max height, and if there is nothing there either, it will use '700'.

Return Value

  • If $url is a valid url to a supported provider, the function returns the embed code provided to it from the oEmbed protocol. Otherwise, it will return false.


Retrieve the embed code for a URL from a supported oEmbed provider:

<?php $embed_code = wp_oembed_get('http://www.youtube.com/watch?v=AbcDeFg123'); ?>

Retrieve the embed code for a URL from a supported oEmbed provider - with width argument:

<?php $embed_code = wp_oembed_get('http://www.youtube.com/watch?v=AbcDeFg123', array('width'=>400)); ?>

Source File

wp_oembed_get() is located in wp-includes/embed.php.

Change Log

Since: 2.9.0


Embeds: wp_oembed_add_provider(), wp_oembed_remove_provider(), wp_oembed_get(), wp_embed_defaults(), wp_embed_register_handler(), wp_embed_unregister_handler(), get_embedded_audio(), get_embedded_media(), get_embedded_video(), wp_embed_handler_audio(), wp_embed_handler_video()