6

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.

4

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";
    }
}
  • 1
    You would also want to run it on the wp-login.php header file also, which is excluded from wp_head ( or seems to be ). Looking for blog_public is a good point though to make it more usable. Thanks! – Howdy_McGee Jan 14 '15 at 23:58
2

I suppose this ended up working for me. I was more hoping for some kind of better filter but it works just as well. Throw this in a functions.php file and you're good to go.

/** No Index No Follow Entire Website **/
function nofollow_meta() {
    echo "<meta name='robots' content='noindex,nofollow' />\n";
}
add_action( 'wp_head', 'nofollow_meta', 1 );
add_action( 'login_enqueue_scripts', 'nofollow_meta', 1 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.