Codex

Function Reference/wp oembed get

Contents

Description

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

Usage

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

Parameters

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

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.

Examples

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/media.php.

Change Log

Since: 2.9.0

Related