Add No Follow To External Links Dynamically

This code will add the rel="nofollow" attribute to all external links. It checks all a href links within the content area in single posts for your domain and adds nofollow when the domain doesn’t match.

Demo Video

Shows the no follow attribute added to external links.

Tested using the Genesis Sample theme by StudioPress however will work in any WordPress child theme by adding a conditional tag after the function name like this :

if ( ! is_singular('post') ) {
}

When using the code in non Genesis themes, add the PHP code to your child themes functions file and delete the single.php file.

Installation Steps – Genesis Users

There’s 2 steps :

  1. # Upload the files named single.php & nofollow.js to your child theme folder like this :
  2.  

  3. # Swap out all instances of wpsites.net in the nofollow.js to your domain.
  4.  

Download Folder

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.