Add Nofollow Attribute To The Link To Comments Generated Thru Wordpress comments_popup_link

Print This Post

If you are developing a Wordpress theme for distribution or for your own blog and you are using the template tag comments_popup_link to display the link to normal post comments or open up comments pop up window, you would definitely like to make those links on blog home page ‘Nofollow’ as there is no need to keep them ‘do follow’, and let the search engine bot crawl them every time it crawls your home page or all important blog pages with these kind of links.

Below is a simple function attached to a Wordpress filter to make all those links ‘No follow’ for the search engines like Google. Add the below code at the very bottom of your active theme’s function.php (Theme functions) and it is all.

<?php function add_nofollow_to_comments_popup_link(){
    return ' rel="nofollow" ';}
add_filter( 'comments_popup_link_attributes', 'add_nofollow_to_comments_popup_link' ); ?>

Illustration Image:-

make comments_popup_link nofollow

What this code does is

It is simple! The function add_nofollow_to_comments_popup_link will add rel=”nofollow” to all the comment links generated by the template tag comments_popup_link, so that all the links are now nofollow.

It is tied to Wordpress filter ‘comments_popup_link_attributes’ which can be used to add various attributes to the comment link generated by the comments_popup_link Wordpress Template tag.

 

Google Buzz
RSS for Internet Techies Hello there! If you are new here, you might want to subscribe to the RSS feed for updates.
Share it
3 Responses to “Add Nofollow Attribute To The Link To Comments Generated Thru Wordpress comments_popup_link”
  1. steve says:

    This works.. but causes an error in the wordpress feed.
    Warning: Cannot modify header information – headers already sent by (output started at /home/xxx/public_html/sitename.co.uk/wp-content/themes/rv/functions.php:356)

    I checked for whitespace in the functions file but there is none.
    Any ideas??

  2. Sean says:

    Thanks, this worked perfectly.

Leave a Reply

If you have any query or question related to Blogging, Wordpress, Monetization thru Adsense, Plugins then kindly post your queries on Internet Techies Forum. We will definitely try to resolve that or some other members from our forum will do. Thanks for the consideration.

(required)

(required)