oEmbed is a powerful feature in WordPress that allows users to easily embed content from other websites by simply pasting the URL into the editor. However, if you’re not using oEmbed or if you want to optimize the performance of your website, you may want to remove the oEmbed-specific JavaScript that WordPress injects into the front-end and back-end of your site.
Removing oEmbed-specific JavaScript from the front-end and back-end in WordPress can help improve website performance and security by reducing the amount of unnecessary code and potential vulnerabilities.
oEmbed is a feature in WordPress that allows users to embed external content, such as videos or social media posts, directly into their posts or pages. This feature requires JavaScript to be loaded on both the front-end and back-end of the website to function properly.
However, if the website does not use oEmbed or relies on alternative embedding methods, this JavaScript code can be removed without affecting the website’s functionality. Removing this code can help improve website speed and reduce the amount of unnecessary code that needs to be loaded, which can have a positive impact on website performance and user experience.
In addition, removing oEmbed-specific JavaScript can also help improve website security by reducing the potential attack surface. Since oEmbed relies on external sources to provide embedded content, it can potentially expose the website to security vulnerabilities or malicious code injection. By removing the oEmbed-specific JavaScript, website owners and administrators can reduce the risk of such attacks.
It is worth noting that removing oEmbed-specific JavaScript may not be suitable for all websites, especially those that rely heavily on external content embedding. Additionally, some themes and plugins may rely on this code to function properly, so it is important to test the website thoroughly after removing this code to ensure there are no adverse effects.
In this tutorial, we’ll show you how to remove oEmbed-specific JavaScript from both the front-end and back-end of your WordPress website. Please note that this tutorial assumes you have some basic knowledge of WordPress and web development.
In WordPress wp_oembed_add_host_js()
adds the necessary JavaScript to communicate with the embedded iframes.
/wp-includes/embed.php adds below code to your site.
function wp_oembed_add_host_js() { wp_enqueue_script( 'wp-embed' ); }
If you have no need to load oEmbed specific Java Script in backend and frontend then you absolutely don’t need that.
On Crunchify, we have disable oEmbed Javascript in frontend and backend.
How to remove oEmbed Javascript in frontend and backend?
Just add below code to your theme’s functions.php file and you are all set.
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
This code removes the wp_oembed_add_host_js action from the wp_head hook, which is responsible for adding the oEmbed-specific JavaScript to your website. Simply add this code to your functions.php file, and the oEmbed-specific JavaScript will be removed from the front-end of your website.
Any other way to disable oEmbed using plugin?
- Download plugin Crunchy Booster Plugin.
- Enable toggle for below two options:
- Remove oEmbed discovery links
- Remove oEmbed-specific JavaScript from front-end & back-end
That’s it. Hope that helps.
Crunchy Booster is the Simplest WordPress Optimizer & Customizer Plugin!
It provides simplest, light weight, most powerful All-in-One 50+ Optimization
, Customization, Webmaster, Database, Configuration, WordPress fine-tuning options in single plugin.