How to remove comment-reply.min.js in WordPress

By default your WordPress site loads a JavaScript file named comment-reply.min.js (/wp-includes/js/comment-reply.min.js) on all of your pages. In some cases you might not be using this if you are using a third party comment system such as Disqus. In my case, I want to use WordPress’s default comment system but I want users to comment on posts only and not on pages (Most of us want this)

You might want to remove comment-reply.min.js file if you have disabled comments completely, disabled nested/threaded comments or moved to a third-party comment system. There can even be a case when you want to remove comment-reply.min.js file from all pages except posts as you don’t need a comment box on your homepage (Most of us don’t have a comment box on the homepage)

Also see:- How to optimize Newspaper theme

Reducing one file (removing comment-reply.min.js) will reduce the page load time and size. When you don’t use comment-reply.min.js file, HTTP request will lower by one (Doesn’t seem cool, right?)

Well, removing any code from a page that exists for nothing and actually does nothing is a good practice. Following are the codes that you can add for two case scenarios. You know yours, add the one that meets yours.

Codes provided below should be added to your active theme’s function.php file or you can also us a plugin like Code Snippets (We use this). We won’t talk on how to use Code Snippets here in this article.

Remove comment-reply.min.js file from all pages

//Remove comment-reply.min.js
 from all pages
add_action( 'wp_enqueue_scripts', 'comment_reply_hook' );
function comment_reply_hook() {
    wp_deregister_script( 'comment-reply' );
}

The above code deregisters / removes comment-reply.min.js file from all of your pages including posts.

Remove comment-reply.min.js file from all pages except posts.

You want to have comment-reply.min.js file on posts and not on other pages like Homepage, About etc? Add the following code:

//Remove comment-reply.min.js from all pages except posts
add_action( 'wp_enqueue_scripts', 'comment_reply_hook' );
function comment_reply_hook() {
  if ( !is_single()) {
    wp_deregister_script( 'comment-reply' );
 }

Above code wont remove comment-reply.min.js file from posts but will remove it from other pages.

That’s it. Now you have remove comment-reply.min.js file according to your need. In our case, we wanted to load the file on posts but not on pages as users comment on posts and not on pages like Homepage and such. So we did what our requirement was. Removing comment-reply.min.js helped us reduce one HTTP header and helped improve loading speed. Get rid of it from pages you don’t want or use in WordPress.