最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

links - How to automatically nofollow a set domains? (I seem to have half of the answer)

programmeradmin2浏览0评论

There we go with my first question ever on WPSE. Hope someone can lend me a hand here :)

I am sick of adding nofollow rel attribute manually on every single outbount link. I´m looking for a code snippet to make external links going from my blog posts into a specific set of external domains nofollow.

This is tricky because I don´t want all external links to become nofollow. Just the ones under specific domains (there´s like 3 domains I want to nofollow).

Any ideas ?

P.S.: Someone had already replied to a similar question How to set all external links to a certain domain to "nofollow"? - I like JMau answer (marked as best answer) except I´m not sure how to insert multiple domain names.

There we go with my first question ever on WPSE. Hope someone can lend me a hand here :)

I am sick of adding nofollow rel attribute manually on every single outbount link. I´m looking for a code snippet to make external links going from my blog posts into a specific set of external domains nofollow.

This is tricky because I don´t want all external links to become nofollow. Just the ones under specific domains (there´s like 3 domains I want to nofollow).

Any ideas ?

P.S.: Someone had already replied to a similar question How to set all external links to a certain domain to "nofollow"? - I like JMau answer (marked as best answer) except I´m not sure how to insert multiple domain names.

Share Improve this question asked Apr 10, 2020 at 19:15 Mario PérezMario Pérez 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Instead of the linked option you could just go with something using jQuery. Try adding something like this to your primary theme or plugin javascript file. (Usually something like main.js.)

jQuery( document ).ready( function($) {
    $( 'a[href^="https://google"], a[href^="https://yahoo"]' ).each( function() {
        $( this ).attr( 'rel', 'nofollow' );
    } );
} );

For any additional URLs you'd simply keep adding a[href^="https://domain"] in a comma separated format into the selector.

发布评论

评论列表(0)

  1. 暂无评论