If you don’t want to index specific posts and pages, categories, and tags of your site, there are two methods to do so. The easiest one is by disallowing through robots.txt. The second is by adding meta tags to disallow pages/posts globally. In manual method we will add the below meta tag to the header of each page you want to block from being indexed.

There is a drawback with the robots.txt blocking method. You can’t block Search Engines from fetching links from ‘noindex’ed pages. You must use a plugin for that OR, use this method as ‘all in one‘ solution for adding both “noindex” and “nofollow” meta tags to specific pages/posts.
<meta name="robots" content="noindex" />
So how do you add it to each and every page without plugins? Well, here is an easy and quick solution.
We will inject this Noindex Meta Tag to specific pages through ‘functions.php’ with simple PHP coding. I have explained most cases folks expect to do with examples.
If this post benefits you, please let us know in the comments. We ‘NoFollow’ your email IDs in the comments 🙂
Mild Warning: Know what you are doing. Applying wrong conditions will De-Index your Already Indexed Posts.
Before proceeding let us just understand what adding the “noindex” does to your site.
Basically, when any URL is already accessible to the public, it is accessible for Search Engines too. You have No Control over what Search Engines Crawl over. You can only tell them whether they should index that page or not. If the page has “noindex” tag, the page will never be indexed.
However, NoFollow is different. This applies to ONLY Links on that page. Here you tell Search Engines through the “NoFollow” tag to visit the page, crawl the page, but not allow them to read Links on that page. Whether you allow them to index or not, is defined by the previous tag, “noindex“
In all the below examples, we are going to add ONLY “noindex” tags to our page headers. If you want to add any other condition like, “nofollow”, “noarchive”, “nosnippet” or any combinations of these, you can add those in the same code below with the same line or by adding another line (if required).
By following this article, you will be able to add the robots meta to the header to any specific post, page, or archive. To confirm whether the code is added perfectly, just search for the below code in the respective page’s source code.
<meta name="robots" content="noindex" />
Serious Warning: Page IDs if wrong will mess up your search ranking. Just double-check.
If you keep the condition empty ( ), it will apply to every content in your site. In the sense, all the pages will have “noindex” tag.
All are PHP Codes, add these to your site using Code Snippets Plugin or directly into child theme’s ‘functions.php’ file.
I also suggest you remove the links which you don’t want to index from Sitemaps as well. Else Search Engine Consoles will show errors.
Table of Contents
Noindex Specific WordPress Post
/* No Index Our Test Post- wpclimax.com/test-post/ */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_post_single');
function wpclimax_header_function_condition_noindex_post_single(){
if ( is_single( '1889' ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
You will add this code just by changing the Page ID in Line 4. You can find your post/page ID in the URL of the Post Edit Page. Every single post, page, tag, has an ID. The other way to find Page ID without editing posts is through source code. Search for “page-id-” in the source code. You will get only one result with Page ID. (This applies to pages only)
To find the ID of posts, search for “postid-” in the source code.
With the source code method, it is difficult to find IDs of archives. Hence use the Edit method itself.
Noindex Multiple WordPress Posts
There are two ways you can achieve this. The second method also works fine. But not efficient to add multiple IDs. In order to efficiently add multiple page IDs, prefer the first method itself.
/* No Index Multiple Posts- wpclimax.com */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_post_multiple');
function wpclimax_header_function_condition_noindex_post_multiple(){
if ( is_single( array( '3241', '3243') ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Alternate Method, which is not wrong, but not preferred since it consumes more time to add multiple IDs. The above array method is preferred by the WordPress community. This same alternate method applies to Pages as well. We have not demonstrated this method again henceforth.
/* No Index Multiple Posts- wpclimax.com (Alternate Method)*/
add_action('wp_head', 'wpclimax_header_function_condition_noindex_post_multiple_2');
function wpclimax_header_function_condition_noindex_post_multiple_2(){
if ( is_single( '3238' ) || is_single( '3239' )) { ?>
<meta name="robots" content="noindex" />
<?php }
};
In both, the above codes, 1889, 3238, 3239, 3241, 3248 are Post IDs. Remove which we have added and enter the correct ones.
You can also use slugs in place of page IDs. Instead of using the page ID for the ‘About Us’ Page, I can use ‘about‘ if it’s the right slug. I suggest the ID method itself. That’s permanent for a post/page. Slugs may change and you can if you wish to.
Noindex Specific WordPress Page
No Explanation is needed. Just replace the is_single() function with is_page(). Don’t keep it empty though 🙂
/* No Index Our Test Page- wpclimax.com/test-page/ */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_page_single');
function wpclimax_header_function_condition_noindex_page_single(){
if ( is_page( '1887' ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex Multiple WordPress Pages
/* No Index Multiple Posts- wpclimax.com */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_page_multiple');
function wpclimax_header_function_condition_noindex_page_multiple(){
if ( is_page( array( '3242', '3244', '3245', '3246') ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex Single Category
With this code, only “noindex” is added to category archives. Not for any posts under that ‘noindex’ed category. The below code will add “noindex” tag to the ‘Uncategorized’ archive of most WordPress websites. The category ID is always ‘1’ for the uncategorized archive.
/* No Index Single Category */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_single_category');
function wpclimax_header_function_condition_noindex_single_category(){
if ( is_category( '1' ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex Multiple Categories
/* No Index Multiple Categories */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_multiple_categories');
function wpclimax_header_function_condition_noindex_multiple_categories(){
if ( is_category( array( '12', '13' ) ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex All Categories
/* No Index All Categories */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_all_categories');
function wpclimax_header_function_condition_noindex_all_categories(){
if ( is_category() ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex Single Tag Archive
Below is very similar to category archives. Here we just replace is_category() with is_tag().
/* No Index Single Category */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_single_tag');
function wpclimax_header_function_condition_noindex_single_tag(){
if ( is_tag( '10' ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex Multiple Tag Archives
/* No Index Multiple Categories */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_multiple_tags');
function wpclimax_header_function_condition_noindex_multiple_tags(){
if ( is_tag( array( '312', '313' ) ) ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex All Tag Archives
/* No Index All Categories */
add_action('wp_head', 'wpclimax_header_function_condition_noindex_all_tags');
function wpclimax_header_function_condition_noindex_all_tags(){
if ( is_tag() ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Noindex Pagination
If you have seen an URL like this, https://example.com/category/page/2 is known as WordPress Paginated URL. If you don’t wish to index these, use the below code.
/* No Index Paginated Pages*/
add_action('wp_head', 'wpclimax_header_function_condition_noindex_paginated');
function wpclimax_header_function_condition_noindex_paginated(){
if ( is_paged() ) { ?>
<meta name="robots" content="noindex" />
<?php }
};
Tips
Do not use is_singular() function unless you specifically need it. It applies to all single Posts, Pages, and Attachments.
You also need to use “else” condition for the is_singular tag when used with an array of post IDs. Or else the code won’t work. Test everything before applying conditions with the is_singular() tag on your site.
As already mentioned, in the same <meta> line you can add “nofollow” tag too. Our ‘Test Post’ is categorized under the ‘uncategorized’ category. We have added both noindex and nofollow to this category page.
If you have something specific to “noindex” or “nofollow”, let us know in the comments below. We would like to take it a try.