Question

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.

Was it helpful?

Solution

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";
    }
}

OTHER TIPS

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 );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top