Wordpress - Remove meta robots tag from wp_head
add_filter('wpseo_robots', 'yoast_no_home_noindex', 999);
function yoast_no_home_noindex($string= "") {
if (is_home() || is_front_page()) {
$string= "index,follow";
}
return $string;
}
this should be fine i think.. somewhere in your theme functions.php and should do the trick.
Based off of your comments on my other answer implying that you explicitly wish to keep "Discourage search engines from indexing this site" enabled, after a more thorough investigation of WordPress core source (particularly default-filters.php), I think this is probably what you were after all along:
add_action( 'posts_selection', 'indexSearchPage' );
function indexSearchPage() {
// Be sure to include the priority for the action or it won't be removed
if( is_search() )
remove_action( 'wp_head', 'noindex', 1 );
}
I use the posts_selection
action hook as it's the first hook in WordPress's loading routine that has access to conditional tags. You can use later actions up to and including wp_head
, but if you use wp_head
itself you need to add the action with a priority less than 1
as noindex
is added with a priority of 1
:
add_action( 'wp_head', 'indexSearchPage', -1 );
Alternately, it is possible to conditionally trick WordPress into thinking that "Discourage search engines from indexing this site" is disabled:
add_action( 'posts_selection', 'indexSearchPage' );
function indexSearchPage() {
if( is_search() ) {
$alloptions = wp_load_alloptions();
$alloptions[ 'blog_public' ] = '1';
wp_cache_set( 'alloptions', $alloptions, 'options' );
wp_cache_set( 'blog_public', '1', 'options' );
}
}