August 8th, 2008
Add Nofollow Tag To WordPress Posts
I must have posted about adding the nofollow tag to WordPress posts about 10 times on various blogs I have run over the years and all those blogs are no longers live, so I thought I would post it once more and just leave it up
Adding the nofollow tag to links in your WordPress posts is actually fairly simple. It is just a matter of adding a little php code into your themes functions.php file, saving and uploading it. Lets get started…
Step 1:
Open your functions.php file of your theme. If you don’t have one, create it and put it in your main theme directory.
Step 2:
Add the following code into the file.
<?php
// Add nofollow tag to links in your posts
function addnofollow($text) {
return str_replace('<a href=', '<a rel="nofollow" href=', $text);
}
add_filter('the_content', 'addnofollow');
?>
IMPORTANT! Make sure that you don’y leave any blank lines after the code. If you do, you will get a nasty php error every time you try view your blog.
Step 3:
Save and upload to your theme directory.
Every time you create links in your WordPress posts they will now have the nofollow tag added to them
Questions, comments, errors? Leave them in the comment box below.
No Comments Yet
Be the first to leave a comment!

























Leave A Comment