How to Load wp-emoji-release.min.js to CDN in WordPress

While you’re optimizing your website, you probably encounter this little code wp-emoji-release.min.js from loading to your website and not loading to your CDN network. (A CDN is use to load all of your static file to other network/server in order for your server to reduce load and cater more visitor to your site than usual.). And there are no options in wordpress to change it links easily.

The last sort option you have is to remove this plugin in order to fully optimize your website. But, there are ways to still use wordpress emoji to load it to a CDN network.

If you’re using Wp Super Cache or Google Pagespeed, it has tool to filter out link and convert it to a cdn link. But The wp-emoji-release.min.js doesn’t automatically converted to a cdn link because the URL is being strip by the include_url() function of wordpress adding a \ on every slash.

To achieve it, we can manually edit the wordpress file. This is by editing the wp-includes/formatting.php file and edit the line 5085 – then change it to your CDN link.

BEFORE:

$settings['source'] = array(
 /** This filter is documented in wp-includes/class.wp-scripts.php */
 'concatemoji' => apply_filters( 'script_loader_src', includes_url( "js/wp-emoji-release.min.js?$version" ), 'concatemoji' ),
 );

AFTER:

$settings['source'] = array(
 /** This filter is documented in wp-includes/class.wp-scripts.php */
 'concatemoji' => apply_filters( 'script_loader_src', "https://yourcdn.com/wp-includes/js/wp-emoji-release.min.js?$version", 'concatemoji' ),
 );

This is not the best solution, but if you have a better one. Please leave comment down below.

1 Comment

  • Andy
    Posted April 21, 2020 9:24 am 0Likes

    Here’s a better solution that uses the filter to change the script location:

    function wr_script_loader_src( $source, $scriptname ) {
    if ($scriptname == ‘concatemoji’) {
    $source = str_replace(get_home_url(), ‘YOUR_DOMAIN’, $source);
    }
    return $source;
    }
    add_filter(‘script_loader_src’, ‘wr_script_loader_src’, 10, 2);

Leave a Reply to Andy Cancel reply

trabzon escort yalova escort Samsun escort izmit escort nazilli escort