How to prevent Yoast from setting noindex on pages

On a few occasions Yoast has inexplicably injected a noindex meta tag in the head of pages that I want search engines to index.

I’ll get to the bottom of this when I have a free block of time. But, but for now, a really simple way to keep the meta tag away, is to add a filter.

Here’s the basic code. Put this in your theme (or better still, in an admin plugin) and it will stop the meta tag from being added to the head:

/**
 * Prevent Yoast from adding a 'noindex' tag
 */
add_filter( 'wpseo_robots', '__return_false' );

Conditionally apply the Yoast filter

Better still, make it conditional by adding a meta field to each page to state whether the page is to be indexed. Then wrap the filter in a function and call it before the page is built. Here’s an ACF solution:

/**
 * Granular Page Index Control
 *
 * Yoast seems to like to throw up a 'noindex' meta tag. We probably don't want it!!!
 */
function maybe_encourage_search_engines() {
    if (function_exists('acf') and get_field('encourage_search_engines')) {
        add_filter( 'wpseo_robots', '__return_false' );
    }
}

I’m not a fan of adding filters, when there’s clearly a better solution, but this is robust and far better than the website’s pages actively being discouraged from valuable search engine indices.

Are you experiencing problems with search engine indexing?

If you’re experiencing a similar problem or just have a hunch that something like this could be negatively impacting on your website, please get in touch and we’ll gladly help. We’re seasoned developers with years of WordPress experience, developing custom themes and plugins, and helping clients with all manner of performance and search engine optimisations.

Reply