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

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.

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.

 

  • http://techzblog.in TECHZBLOGin

    thx..

  • steve

    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??

  • Sean

    Thanks, this worked perfectly.

  • http://organizedfamilies.com Ryan

    Excellent post. This is just what I was looking for and it worked like a charm on all the right pages. Thanks a lot.

  • John Jones

    Well I copied and pasted that code and put it into the bottom of the theme function.php file and now I can’t even log into my site at all. All it says is:
    “Parse error: syntax error, unexpected ‘<' in /home/content/87/4644587/html/wp-content/themes/fluid-blue/functions.php on line 10"
    I can't login to my site or do anything and I'm not a tekkie. Any idea how to fix this?