javascriptjquerywordpressseonofollow

how to add rel=nofollow to some specific external links in wordpress


The small banners loaded on the site of the page does not have the rel="nofollow" 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' );" href="DYNAMIC URL"><img alt="" src="DYNAMIC IMG PATH"></a>  

I want them to be changed to:

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

Basically I want to add rel="nofollow" to links of sidebar banners only.

Also i don't want to use Plugin.


Solution

  • 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