Blog WordPress How to Disable wp-embed.min.js and wp-emoji-release.min.js

How to Disable wp-embed.min.js and wp-emoji-release.min.js

by Sa'ed Hammad

Disabling WP Embeds and WP Emojis are one of a lot of WordPress performance optimizations and tweaks you can do to improve your website loading time.

Firstly, let’s take a look at what is WP Embeds then WP Emojis

WP Embeds:

It is responsible for converting links into embed frames like embed videos, images, tweets, audio, and other content into your WordPress site.

wp-embed.min.js does not relate to embedding oEmbed content from other providers: Vimeo, YouTube, etc. You can remove wp-embed.min.js and those embeds will continue to function.

wp-embed.min.js hides the blockquote and reveals the iframe. if removing the wp-embed.min.js script from your website using the below method then reload your page and you’ll notice that the blockquote is visible but the iframe is hidden.

In this article, we will disable wp-embed.min.js and wp-emoji-release.min.js with the code method, if you are not familiar with codes check with a developer first.

Disable wp-embed.min.js

We recommend doing it if you have a child theme.
at child theme > functions.php > add a code

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;
}

WP Emojis

Emoji are the ideograms and smileys that are used in electronic messages and Web pages. It is unnecessary at all and adds additional load time.

Disable wp-emoji-release.min.js

at child theme > functions.php > add a code

function disable_emojis() {
 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
 remove_action( 'wp_print_styles', 'print_emoji_styles' );
 remove_action( 'admin_print_styles', 'print_emoji_styles' ); 
 remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
 remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); 
 remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
 add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
 add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
}
add_action( 'init', 'disable_emojis' );

/**
 * Filter function used to remove the tinymce emoji plugin.
 * 
 * @param array $plugins 
 * @return array Difference betwen the two arrays
 */
function disable_emojis_tinymce( $plugins ) {
 if ( is_array( $plugins ) ) {
 return array_diff( $plugins, array( 'wpemoji' ) );
 } else {
 return array();
 }
}

/**
 * Remove emoji CDN hostname from DNS prefetching hints.
 *
 * @param array $urls URLs to print for resource hints.
 * @param string $relation_type The relation type the URLs are printed for.
 * @return array Difference betwen the two arrays.
 */
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
 if ( 'dns-prefetch' == $relation_type ) {
 /** This filter is documented in wp-includes/formatting.php */
 $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );

$urls = array_diff( $urls, array( $emoji_svg_url ) );
 }

return $urls;
}

If you don’t use a child theme or you want to add it on another way you could add it via the Code Snippets plugin

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.