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
Adding a custom oEmbed link type
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; }
Removing a specific oEmbed link type
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; }
Replacing the entire list of oEmbed link types
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; }
Filtering oEmbed link types based on a condition
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; }); }
Logging the current oEmbed link types
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; }