Ad

How To Add Rel=nofollow To Some Specific External Links In Wordpress

- 1 answer

The small banners loaded on the site of the page does not have the attribute - and we would like this to be added.

http://poltr.com/?s=dans&post_type=aktivitet is the link, you can see the sidebar banners, they are curently set to:

just an example:

<a onclick="ga('send', 'event', 'koebenhavn', 'click', 'DYNAMIC URL' );" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="DYNAMIC URL"><img alt="" src="DYNAMIC IMG PATH"></a>  

I want them to be changed to:

<a  onclick="ga('send', 'event', 'koebenhavn', 'click', 'DYNAMIC URL' );" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="DYNAMIC URL"><img alt="" src="DYNAMIC IMG PATH"></a>

Basically I want to add to links of sidebar banners only.

Also i don't want to use Plugin.

Ad

Answer

This can be done by simple javascript code

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

Add this to your footer.php file this will add attribute to all tags.

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

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

Hope this will do

Ad
source: stackoverflow.com
Ad