4

I have WP website with multiple campaign landing pages made with Page Builder. All campaign pages are under /campaign/ so urls are always type http://example.com/campaign/some-landing-page Now I would like to noindex by default all pages which url contains /campaign/ but I can't figure out how to do this with Yoast SEO. I managed to noindex all pages via Yoast settings but I only want to noindex those with /campaign/

1
2

There seem to be several ways to achieve this, but none will simply work out of the box, because each environment is different.

Depending on your specific circumstances, you could use one of the following options.

Add "noindex" in robots.txt

Use the robots.txt file and add the directives there to disallow everything under /campaign/, as suggested by Kristian Svensson.

Add "noindex" to specific categories in functions.php

According to Yoast, you can set noindex for the category-page itself, but it isn't possible to set noindex for all posts in that category.

However, if /campaign/ is a category, add the following snippet in your functions.php file, if you have access to it:

function add_noindex( $content ) { if( is_single() && in_category(array(value))) { return '<meta name="robots" content="noindex, nofollow">'.$content; } else return $content; } add_filter("the_content","add_noindex");

And replace value with either the category ID, or the name of the category (in quotes). Separate multiple categories with a comma.

Add "noindex" to specific categories in header.php

<?php if (is_single() && in_category(array(457)))  { 
echo '<meta name="robots" content="noindex, follow">';
} ?>

Replace 457 with the category ID of /campaign/, if it's a category.

Based this Github thread.

1

Unfortunately I can't see that it is possible with Yoast unless you manually set each page to noindex manually.

However, if you have access to your website root with ftp or a file manager on your webserver you can do it quite easy with a robots.txt file. In that file you can give Google bot and other search engines instructions to what they are allowed (or not allowed) to crawl and index.

To prevent all bots to index all content in the /campaign/ folder you need to add the following:

User-agent: *
Disallow: /campaign/

Save it and test it in your Google Search Console (if you have it). That's it.

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.