Using WordPress ‘oembed_linktypes’ PHP filter

The oembed_linktypes WordPress PHP filter allows you to modify the array of supported oEmbed link types.

Usage

add_filter('oembed_linktypes', 'your_custom_function');
function your_custom_function($format) {
  // your custom code here
  return $format;
}

Parameters

  • $format (string[]): An array of oEmbed link types. Accepts ‘application/json+oembed’, ‘text/xml+oembed’, and ‘application/xml+oembed’ (incorrect, used by at least Vimeo).

More information

See WordPress Developer Resources: oembed_linktypes

Examples

Add a new oEmbed link type to the existing list.

add_filter('oembed_linktypes', 'add_custom_oembed_linktype');
function add_custom_oembed_linktype($format) {
  $format[] = 'text/html+oembed';
  return $format;
}

Remove ‘application/xml+oembed’ from the list of supported oEmbed link types.

add_filter('oembed_linktypes', 'remove_specific_oembed_linktype');
function remove_specific_oembed_linktype($format) {
  $key = array_search('application/xml+oembed', $format);
  if ($key !== false) {
    unset($format[$key]);
  }
  return $format;
}

Replace the default oEmbed link types with a new list.

add_filter('oembed_linktypes', 'replace_oembed_linktypes');
function replace_oembed_linktypes($format) {
  $format = ['text/html+oembed', 'application/json+oembed'];
  return $format;
}

Only allow JSON oEmbed link types.

add_filter('oembed_linktypes', 'allow_only_json_oembed_linktypes');
function allow_only_json_oembed_linktypes($format) {
  return array_filter($format, function($item) {
    return strpos($item, 'json') !== false;
  });
}

Log the current oEmbed link types for debugging purposes.

add_filter('oembed_linktypes', 'log_oembed_linktypes');
function log_oembed_linktypes($format) {
  error_log(print_r($format, true));
  return $format;
}