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_providers filter
Since WordPress 4.4, oEmbed discovery is enabled for all users and allows embedding of sanitized iframes. The providers in this list are sanctioned, meaning they are trusted and allowed to embed any content, such as iframes, videos, JavaScript, and arbitrary HTML.
To use oembed_providers filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin. It’s always a good practice 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_providers_defaults which takes 1 parameter and is registered using add_filter. The first parameter oembed_providers is the name of the hook, the second parameter weplugins_modify_oembed_providers_defaults is the name of the function which 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 oembed_providers filter.
Example 1: Basic Usage
This example shows how you can use the oembed_providers filter to modify the list of providers.
function weplugins_modify_oembed_providers_defaults($providers) { // Update the $providers variable according to your website requirements and return this variable. return $providers; } // add the filter add_filter( "oembed_providers", "weplugins_modify_oembed_providers_defaults", 10, 1 );
Example 2: Removing a Hook
This example demonstrates how to remove a hook callback.
remove_filter( "oembed_providers", "weplugins_modify_oembed_providers_defaults", 10, 1 );
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Example 3: Conditional Modification
You can also modify the providers conditionally based on certain criteria.
function weplugins_modify_oembed_providers_conditionally($providers) { // Add custom logic to modify $providers based on conditions. if (some_condition()) { // Modify $providers } return $providers; } // add the filter add_filter( "oembed_providers", "weplugins_modify_oembed_providers_conditionally", 10, 1 );
If you’re having any trouble using this hook or need customization, please contact our WePlugins Development Team and we’d be happy to assist you.
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.