Adding rel=”nofollow” to WP functions

Recently, one of my clients requested me add a rel=”nofollow” argument in the about page of his site. WordPress by default only adds that to its comments section to prevent spam marketing. There might be various ways doing so but I found it pretty difficult to find a good solution in this case. Why? Because the page list wasn’t being called directly using wp_list_pages(). It used a custom function. Not only that, due to some customization to the function, it also used a php variable in the parameter.

I searched for a solution and found a plugin called add link attribute. But the examples and some solutions were quite simple and didn’t address my problem. I tried a few things, sending multiple arguments ‘straight’ worked but not with a variable (maybe someone can help me here). So, I searched for other solutions.

Luckily, I found one (for tags) and it was easy to implement. I simply replaced that function to the client’s need and pasted over to functions.php and it worked like a charm. :)

function add_nofollow($text) {
    return 
str_replace('<a href=''<a rel="nofollow" href=',  $text);    
}

add_filter('wp_list_pages''add_nofollow');

Hopefully, if you are also troubled like me you found the solution. Do post here if you find a better one.

Thanks!

2 thoughts on “Adding rel=”nofollow” to WP functions

  1. Thank before has share about do follow, But I still don’t understand how to sign a site then included it as no-follow or do follow one. Give me the explanation please.