How to nofollow links in default related posts widget of WordPress

Find the file default-widgets.php in wp-includes folder of WordPress Installation. Keep a backup of the original file incase you make mistake. Find the following lines of code under Recent_Posts widget class

<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>

Change it to these. We have added the rel=”nofollow” attribute for the link elements of related post links

<li><a rel="nofollow" href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>

Refresh the WordPress posts or pages where you have configured the default related posts widget. The links of the Widget have become nofollowed.

3 thoughts on “How to nofollow links in default related posts widget of WordPress

  1. flappy bird

    You have some dedicated information throughout this text. I even have
    extraordinarily enjoyed your views on this subject. you are a precocious
    author. Thank you.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>