0

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?

1

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 
);
0

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

0

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

echo wp_rel_nofollow($part_cur_auth_obj->description);
  • This changed the description url like this <a href="\&quot;example.org\&quot;" rel="\&quot;nofollow\&quot;">example</a> – Usman Siddiqui Feb 1 '17 at 7:50
  • print_r($part_cur_auth_obj->description) first and share with me the output. – Samuel Elh Feb 1 '17 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.