1. Home
  2. Knowledge Base
  3. How to NoIndex All Posts in a Category

How to NoIndex All Posts in a Category

Rank Math’s Titles & Meta settings let you set noindex to all posts or to all category pages. But if you want to set noindex to all posts that are assigned to a specific category, then the above settings will not be of any help.

In this knowledgebase article, we’ll show you how you can set noindex to all posts in a specific category with Rank Math.

1 Using a Filter

The first method lets you add a code snippet to your website to set a noindex for all posts within a category.

1.1 Navigate to Theme Editor

To get started, navigate to Appearance > Theme Editor inside your WordPress dashboard.

Navigate to Theme Editor

The right side of the screen shows all your theme files. You can add the code snippet to the functions.php file or rank-math.php file inside your theme folder. We prefer adding the code to the rank-math.php file, and if you haven’t created the file, you can follow this tutorial to create your rank-math.php file in your theme’s folder using FTP or cPanel File Manager.

1.2 Add the Code Snippet

 * Filter to set noindex to specific categories
add_filter( 'rank_math/frontend/robots', function ( $robots ) {
	$categories = array_map( function ( $category ) {
		return $category->slug;
	}, get_the_category() );
	if ( in_array( 'your_category', $categories ) ) {
		unset( $robots['index'] );
		$robots['noindex'] = 'noindex';
	return $robots;
} );

In the above code snippet, replace your_category with your category slug. For this tutorial, we’re using a posts category named ‘WordPress Plugins’. Hence, we would replace your_category in the code snippet with the slug of the category ‘WordPress Plugins’.

To find the category slug, you can navigate to Posts > Categories inside your WordPress dashboard.

Category slug in WordPress

You can find the slug of each category against their category name. Copy and paste the slug in the above code snippet. Once you’ve added the code, update the file to reflect the changes.

Add the code snippet to rank-math.php file

Now, you can check the source code of your posts assigned to the specific category, noindex meta tag would have been added.

Set noindex for posts in a category

Note: Once you’ve added the code snippet to set noindex, any attempt to override a specific post inside the WordPress editor by setting index robots meta tag will not work. The post will continue to show noindex in the front-end until you remove the code snippet.

2 Using the Bulk Actions PRO

While the above filter lets you set noindex to all posts from a specific category in one go, using Bulk Actions with Rank Math can give you more flexibility. It lets you check the posts that will be affected by the changes and you can even exclude some posts from being set with noindex. The Bulk Actions feature is available only for Rank Math PRO users. If you don’t have a PRO license yet, you can get started with a PRO membership of your choice.

2.1 Open Posts

Open Posts from your WordPress Admin menu.

Posts in WordPress dashboard

2.2 Select the Category

From the Categories filter, select the category you wanted to set posts with noindex, and then click the Filter option.

FIlter posts by category in WordPress

Now only the posts that belong to this specific category will be displayed, and the rest will be filtered out.

Category filter applied for WordPress posts

2.3 Set to NoIndex

Now, select the posts that you want under this category to set noindex. The checkbox available at the top left corner will let you select/unselect all the posts inside your visible area. While the checkbox before each post will let you select/unselect the specific post. You can use this option to exclude specific posts while trying to set posts in a category with noindex.

Selecting posts in WordPress posts

From the Bulk Actions drop-down list, select Set to noindex and then click the Apply button.

Set posts to noindex with bulk actions

Now all the selected posts will be set to noindex.

No Index set with bulk actions

Note: Unlike the previous case with using a filter, you can override the robot settings of the individual posts. And any new post created after using the Bulk Actions to set noindex will follow the robots meta settings from Titles & Meta settings inside Rank Math. So what it means is that when new posts are created, you’ll have to use Bulk Actions once again to set them to noindex.

And, that’s it! We hope the tutorial was helpful in setting noindex to all posts in a category. If you still have any questions, feel free to reach our support team, as we’re always here to help.

Still not using Rank Math?

Setup takes less than 5 minutes including the import from your old SEO Plugin!

Know more about the PRO Version

Was this article helpful?

Still need help?


Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket