wp_oembed_get

Home » Functions » wp_oembed_get

Function Name: wp_oembed_get

The wp_oembed_get function is a WordPress function used to retrieve the HTML content of an embedded object based on its URL. It is used to embed media from external sites into WordPress pages and posts by pasting a URL into the content editor.

This function retrieves the HTML content of the embedded object by sending a request to the oEmbed provider and parsing the response. The oEmbed provider is a service that provides data about embedded objects and generates HTML for embedding them.

This function accepts two parameters: the URL of the embedded object and an array of optional arguments. The optional arguments can be used to customize the output of the embedded object, such as setting the maximum width or height of the object, enabling autoplay, or hiding certain elements.

Example Usage:

Let’s say you want to embed a YouTube video on your WordPress site, you can use the wp_oembed_get function to retrieve the HTML content of the embedded video. Here’s how you would use the function:

$video_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
$embed_code = wp_oembed_get($video_url, array(
   'maxwidth' => 600,
   'autoplay' => true
));
echo $embed_code;

In this example, the function retrieves the HTML content of the embedded YouTube video with a maximum width of 600 pixels and autoplay enabled. The resulting $embed_code variable contains the HTML code for embedding the video, which can be displayed on the WordPress site using the echo statement.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.