Remove comment-reply.js and .recentcomments from WordPress Header

Have you ever seen the following code inside the HEAD section of your WordPress blog source code like image above? (It’s appear in single post page only). Now let’s view the css code below, it’s appear in the HEAD section too, when the Recent Comments Widget used

.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}

Ever wonder how it got there, and how to get rid of it?

Remove or Disable Recent Comments Widget CSS code

Why they did not just drop this altogether is a mystery. This leaves a bad taste in my mouth because:

  • the style is automatically forced into any page that embeds the widget
  • it uses !important to override any existing styles
  • it cannot be configured from the widget
  • this is a core WordPress widget and not some widget added by a random plugin. WordPress should not contain such bad practices.
  • It is something that should be handled via a style sheet.

Remove comment-reply.js from WordPress header
Fortunately, we can remove or disable it by adding a filter via the WordPress add_filter() method. In fact, if you look at the TwentyTen theme that comes with the later versions of WordPress 3.0 and on, you will find that theme addresses this issue with the following snippet of code in their functions.php file:
[gist id=2887406]
Drop this code into your functions.php file and the styling will be removed from your HEAD section.

Remove or Disable comment-reply.js code

Let’s see what is place above in header.php

<?php if (is_singular()) wp_enqueue_script('comment-reply'); ?>
        <?php wp_head(); ?>
</head>

Now, we can remove or disable this script more easily by delete this direct from header.php or use wp_deregister_script() function

function clean_header(){
	wp_deregister_script('comment-reply');
         }
add_action('init','clean_header');

Conclusion

Almost parts of WordPress template codes is modifiable or removable by add or remove filter methods in functions.php file. Let’s think about it before hacking to WordPress core sources or create your own WordPress child themes.

2 thoughts on “Remove comment-reply.js and .recentcomments from WordPress Header”

  1. I don’t know whether it’s just me or if perhaps everyone else encountering problems with your website. It appears as if some of the written text in your content are running off the screen. Can somebody else please comment and let me know if this is happening to them too? This might be a problem with my internet browser because I’ve had this happen before. Appreciate it

    • I guess the problem is Google PageSpeed service. I’ve used it on my website and some location is not loading correctly. That’s why the layout has some problem.
      I’ll trying to remove it in next version of NARGA FRAMEWORK

Comments are closed.