As wikipedia notes nofollow is a value that can be assigned to the rel attribute of an HTML element to instruct some search engines that a hyperlink should not influence the link target’s ranking in the search engine’s index.

Occasionally you may need to nofollow all the links in articles,For example if you complied a list post with several links then its good to nofollow all links.In such case its a tedious job to assign nofollow values to each link,So here is a little trick that can easily nofollow all links in posts under particular category or tag.

Nofollow All links under Particular Category

First you need to find the Category ID.Here is how you can find Category ID in WordPress.

function nofollow_cat_posts($text) {
global $post;
        if( in_category(1) ) { // SET CATEGORY ID HERE
                $text = stripslashes(wp_rel_nofollow($text));
        }
        return $text;
}
add_filter('the_content', 'nofollow_cat_posts');

In above code, paste the Category ID in line 3 .For example if your category ID is 255 then the line should be modified as

if( in_category(255) ) {

Now paste the modified code in your themes functions.php (Also works on Genesis Framework).

Now go to any post under the category you nofollowed and see the page source.You will see added rel="nofollow" attribute in all links.

Nofollow All links under Particular Tag

As you did above,You need to find the tag ID.Here is how you can find Tag ID in WordPress.

function nofollow_cat_posts($text) {
global $post;
        if( has_tag(1) ) { // SET TAG ID HERE
                $text = stripslashes(wp_rel_nofollow($text));
        }
        return $text;
}
add_filter('the_content', 'nofollow_cat_posts');

In above code, paste the Tag ID in line 3 .For example if your Tag ID is 255 then the line should be modified as

if( has_tag(255) ) {

Now paste the modified code in your themes functions.php (Also works on Genesis Framework).

Now go to any post under the Tag you nofollowed and see the page source.You will see added rel="nofollow" attribute in all links.

via WPRecipes

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge