wordpress search should not return no-index'd pages

470 views Asked by At

I am using the wonderful Yoast plugin for all sorts of things, but largely to no-index and no-follow pages. We are a PPC based site so therefore we removed search. Now the client wants it back in but I need the wordpress built-in search NOT to return a large number of no-indexed pages.

I know you can build in to exclude various meta descriptions.

I was going to adapt this as a start: https://css-tricks.com/forums/topic/using-wps-pre_get_posts-to-exclude-post-with-meta_key/

Question - What is the term I am looking for - meta-no-index=no??

Why doesn't Yoast do this by default?

1

There are 1 answers

0
i_a On

You'll need to edit the robots meta tag that is outputted by the wp_head() function.

If using Yoast, this is the WP filter to change the robots meta tag content:

add_filter('wpseo_robots', 'yoast_no_search_noindex', 999);
function yoast_no_search_noindex($string= "") {
    if (is_search()) {
        $string= "index,follow";
    }
    return $string;
}

https://wordpress.stackexchange.com/questions/136220/remove-meta-robots-tag-from-wp-head