NoFollow Entire Website

By default whenever you disable indexing via Admin Settings

[ x ] Discourage search engines from indexing this site

It adds a meta tag in the header like so:

<meta name="robots" content="noindex,follow" />

How do I change that to be nofollow instead of follow? I find it odd it enables “follow” and overall want it noindex,nofollow.

I could echo directly into wp_head but this doesn’t account for pages such as wp-login and the likes.

2 s
2

Thought this was a great question so I went digging. In default-filters.php on line 208 there’s add_action('wp_head', 'noindex', 1); as of WordPress 4.1. The noindex() function in turn checks to see if you have set blog_public option to 0. If you have, it calls wp_no_robots() which is simply:

function wp_no_robots() {
    echo "<meta name="robots" content="noindex,follow" />\n";
}

Neither of last methods are filterable, but a simple plugin will do the trick to remove the hook:

/*
 * Declare plugin stuff here
 */

remove_action('wp_head','noindex',1);

Now, you’re free to hook your own action on to echo out what you want.

add_action('wp_head', 'my_no_follow', 1);

function my_no_follow() {
    if ( '0' == get_option('blog_public') ) {
        echo "<meta name="robots" content="noindex,nofollow" />\n";
    }
}

Leave a Comment