Need an SEO Expert? Get Your Free Strategy Session?
Skip to main content

security

How to remove oembed wp functions code without a plugin

Est. reading time: 2 minutes

Quick Answer: How to Remove oEmbed WP Functions Code Without a WordPress Plugin in 2025 The oEmbed feature allows users to embed content from another third-party site with just a URL.

How to Remove oEmbed WP Functions Code Without a WordPress Plugin in 2025

The oEmbed feature allows users to embed content from another third-party site with just a URL. You just need to place the source URL in the content area, then WordPress will automatically turn it into an embed and display it on your page as a live preview of the source.

You may have seen Youtube videos or some tweets displayed on third-party sites. If WordPress powers the site, chances are they are using the oEmbed feature that WordPress has merged since WordPress 4.4.

If you think you don’t need the oEmbed feature for your WordPress site, you may want to disable the feature to improve your site’s overall load time since every time you load a page, it generates an additional HTTP request on your WordPress site to load the wp-embed.min.js file. The request itself is sometimes a bigger deal than the content download size because things like these add up over time.

Disabling Embeds in WordPress Using Code Instead of a Plugin

Before you get started, you may want to backup your site and utilize a child theme to avoid breaking the parent theme or losing your changes when you update your theme.

Once you have opened up the file, then add the following custom code to the child theme (or parent theme if you don’t utilize a child theme) function.php file.



function disable_embeds_code_init() {

 // Remove the REST API endpoint.
 remove_action( 'rest_api_init', 'wp_oembed_register_route' );

 // Turn off oEmbed auto discovery.
 add_filter( 'embed_oembed_discover', '__return_false' );

 // Don't filter oEmbed results.
 remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );

 // Remove oEmbed discovery links.
 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

 // Remove oEmbed-specific JavaScript from the front-end and back-end.
 remove_action( 'wp_head', 'wp_oembed_add_host_js' );
 add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );

 // Remove all embeds rewrite rules.
 add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );

 // Remove filter of the oEmbed result before any HTTP requests are made.
 remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
}

add_action( 'init', 'disable_embeds_code_init', 9999 );

function disable_embeds_tiny_mce_plugin($plugins) {
    return array_diff($plugins, array('wpembed'));
}

function disable_embeds_rewrites($rules) {
    foreach($rules as $rule => $rewrite) {
        if(false !== strpos($rewrite, 'embed=true')) {
            unset($rules[$rule]);
        }
    }
    return $rules;
}