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.