Using WordPress ‘oembed_discovery_links’ PHP filter

The oembed_discovery_links WordPress PHP filter modifies the HTML of the oEmbed discovery links.

Usage

add_filter('oembed_discovery_links', 'your_custom_function');
function your_custom_function($output) {
  // Your custom code here
  return $output;
}

Parameters

  • $output (string) – HTML of the discovery links

More information

See WordPress Developer Resources: oembed_discovery_links

Examples

Remove all oEmbed discovery links from the site.

add_filter('oembed_discovery_links', 'remove_oembed_links');
function remove_oembed_links($output) {
  return '';
}

Add a “data-custom-attribute” attribute to the oEmbed discovery links.

add_filter('oembed_discovery_links', 'add_custom_attribute_to_links');
function add_custom_attribute_to_links($output) {
  return str_replace('<link', '<link data-custom-attribute="example-value"', $output);
}

Add a query parameter to oEmbed discovery link URLs.

add_filter('oembed_discovery_links', 'modify_oembed_link_urls');
function modify_oembed_link_urls($output) {
  $output = preg_replace_callback('/href="([^"]+)"/', function($matches) {
    return 'href="' . $matches[1] . '?custom_param=value"';
  }, $output);
  return $output;
}

Add an additional oEmbed discovery link with a custom URL.

add_filter('oembed_discovery_links', 'add_custom_oembed_link');
function add_custom_oembed_link($output) {
  $custom_link = '<link rel="alternate" type="application/json+oembed" href="https://example.com/custom_oembed.json" />';
  return $output . $custom_link;
}

Wrap all oEmbed discovery links in a div with a custom class.

add_filter('oembed_discovery_links', 'wrap_oembed_links_in_div');
function wrap_oembed_links_in_div($output) {
  return '<div class="custom-oembed-links">' . $output . '</div>';
}