Question

I have this code in author.php file

echo $part_cur_auth_obj->description;

How can i parse the echo so the links within the author description will have the rel="nofollow" attribute set automatically?

Was it helpful?

Solution

If you want to add rel="nofollow" to all the links, then you can simply use str_replace():

echo str_replace( 
  '<a href=', 
  '<a rel="nofollow" href=', 
  $part_cur_auth_obj->description 
);

OTHER TIPS

You can do this simply by javascript code, Add this to your footer.php file this will add attribute to all tags.

$( document ).ready(function() {
        $('body > a').attr('rel','nofollow')
    });

Or can be done by using ID's for particular tags

$( document ).ready(function() {
        $('body > a#ID_OF_A_TAG').attr('rel','nofollow')
    });

make sure you have pasted correct ID of <a id="MY_ID">tag. MY_ID in this case

You can always benefit from pre-defined WordPress functions, see wp_rel_nofollow

echo wp_rel_nofollow($part_cur_auth_obj->description);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top