Using WordPress ‘get_oembed_endpoint_url()’ PHP function

The get_oembed_endpoint_url WordPress PHP function retrieves the oEmbed endpoint URL for a given permalink.

Usage

get_oembed_endpoint_url($permalink, $format);

Example:

$permalink = 'https://example.com/my-post';
$format = 'xml';
$endpoint_url = get_oembed_endpoint_url($permalink, $format);

Parameters

  • $permalink (string) – Optional. The permalink used for the URL query argument. Default: ''.
  • $format (string) – Optional. The requested response format. Default: 'json'.

More information

See WordPress Developer Resources: get_oembed_endpoint_url

Examples

Get oEmbed endpoint URL with default format (JSON)

This code retrieves the oEmbed endpoint URL for a given permalink, using the default JSON format.

$permalink = 'https://example.com/my-post';
$endpoint_url = get_oembed_endpoint_url($permalink);

Get oEmbed endpoint URL with XML format

This code retrieves the oEmbed endpoint URL for a given permalink, using the XML format.

$permalink = 'https://example.com/my-post';
$format = 'xml';
$endpoint_url = get_oembed_endpoint_url($permalink, $format);

Get oEmbed endpoint base URL

This code retrieves the oEmbed endpoint base URL by passing an empty string as the first argument.

$endpoint_base_url = get_oembed_endpoint_url('');

Get oEmbed endpoint URL for the current post

This code retrieves the oEmbed endpoint URL for the current post.

global $post;
$permalink = get_permalink($post->ID);
$endpoint_url = get_oembed_endpoint_url($permalink);

This code retrieves the oEmbed endpoint URL for a given permalink and displays it as a hyperlink.

$permalink = 'https://example.com/my-post';
$endpoint_url = get_oembed_endpoint_url($permalink);
echo '<a href="' . esc_url($endpoint_url) . '">oEmbed Endpoint</a>';