This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
oembed_linktypes filter
Filters the link types that contain oEmbed provider URLs.
To use the `oembed_linktypes` filter, first, you have to register it using `add_filter`. You can write this code into the functions.php of your activated theme or in a custom WordPress Plugin.
WePlugins always prefer to create a custom WordPress Plugin while using hooks, so nothing breaks when you update your WordPress Theme in the future.
In the below live example, we have defined a function `weplugins_modify_oembed_linktypes_defaults` which takes 1 parameter and we registered it using `add_filter`. The first parameter `oembed_linktypes` is the name of the hook, the second parameter `weplugins_modify_oembed_linktypes_defaults` is the name of the function that needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed in the registered function.
Sometimes, you have to remove a registered hook, so you can use `remove_filter` to remove the `oembed_linktypes` filter.
Parameters
- $format: (string[]) Array of oEmbed link types. Accepts ‘application/json+oembed’, ‘text/xml+oembed’, and ‘application/xml+oembed’ (incorrect, used by at least Vimeo).
Below, the 1 parameter is required to use this hook.
Live Example
Below is an example of how you can use this hook.
function weplugins_modify_oembed_linktypes_defaults($format) { // Update the $format variable according to your website requirements and return this variable. You can modify the $format variable conditionally too if you want. return $format; } // add the filter add_filter("oembed_linktypes", "weplugins_modify_oembed_linktypes_defaults", 10, 1);
To remove a hook callback, use the example below.
remove_filter("oembed_linktypes", "weplugins_modify_oembed_linktypes_defaults", 10, 1);
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Example 1: Adding a New oEmbed Link Type
Here’s how you can add a new oEmbed link type to the existing array.
function weplugins_add_new_oembed_linktype($format) { $format[] = 'application/x-my-custom-oembed'; return $format; } add_filter("oembed_linktypes", "weplugins_add_new_oembed_linktype", 10, 1);
Example 2: Removing an Existing oEmbed Link Type
This example shows how you can remove an existing oEmbed link type from the array.
function weplugins_remove_existing_oembed_linktype($format) { if(($key = array_search('application/json+oembed', $format)) !== false) { unset($format[$key]); } return $format; } add_filter("oembed_linktypes", "weplugins_remove_existing_oembed_linktype", 10, 1);
Example 3: Conditional Modification of oEmbed Link Types
Modify the oEmbed link types conditionally based on certain criteria.
function weplugins_conditional_modify_oembed_linktypes($format) { if (is_admin()) { $format[] = 'application/x-admin-custom-oembed'; } else { $format[] = 'application/x-frontend-custom-oembed'; } return $format; } add_filter("oembed_linktypes", "weplugins_conditional_modify_oembed_linktypes", 10, 1);
Contact Us
If you need any customization or are having trouble using this hook, please contact us.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.