How to Disable Search Indexing for a Single Post in WordPress

Posted on Updated on

If you don’t want search engines to index your blog for whatever reason, it’s easy to enable the “no indexing” feature in WordPress located under Settings ->Reading->Search Engine Visibility. But enabling this option will affect every single page on your website. Sometimes however, you just need to prevent one particular page from showing up on search engines like Google. There’s no inbuilt WordPress method  to achieve this though certain themes like Genesis include it as part of the default functionality:

genesis has noindex

Luckily for us, WordPress is customizable enough for us to easily create a function to prevent just a single post or page from being indexed by spiders. The exact technique you use will depend on whether this is a one-off requirement, or if you’ll be doing this on a regular basis. Let’s look at both techniques.

One-off Page Removal from Google

If you’re pretty sure that this is going to be an exception and you’re not going to require this functionality multiple times in the future, it’s easy to create a single hack that hard codes the post ID into the code in functions.php. The first step of course is to find out what that post ID is. Open it up for editing in WordPress and take a look at the URL in the address bar. The post ID will be visible in the first query variable as shown here:

get post id

In this example, my post ID is 4131. To prevent this page from being indexed by search engines, open up your functions.php file and insert the following code:

function add_noindex_to_posts() {

	if (get_the_ID() == 4131)
		echo '<meta name="robots" content="noindex">';


add_action('wp_head', 'add_noindex_to_posts');

In the above code, replace the bolded number 4131 with your own post ID that you obtained in the previous step. If you’re not sure of how to add custom code in WordPress, take a look at my earlier tutorial on the same.

This simple snippet will disable indexing for one particular post. It works great for a one-shot solution. But what if you’re going to need this functionality in the future for other posts as well?. We don’t want to keep on editing code and adding new lines each time we require it. The best way to solve this problem in my opinion is to use custom variables.

Scalable Solution to Disable Indexing on Specific Posts

Open the post you want to prevent from appearing in search results in the WordPress editor and scroll all the way down until you find the “Custom Fields” section. Here, click “Enter New”.

enter new custom value

This will open up a place for you to enter a parameter/value combo. In the text box on the left-hand side type in do_not_index and on the right-hand side, give any value like “true”.

value doesn't matter

Once done, click the “Add Custom Field” button to save the parameters. Now save the entire post itself.

Once done, navigate to functions.php as before and paste the following code:

function add_noindex_to_posts() {

	if(get_post_meta(get_the_ID(), 'do_not_index', true))
		echo '<meta name="robots" content="noindex">';


add_action('wp_head', 'add_noindex_to_posts');

This snippet hooks into the wp_head action and checks each post for the custom value “do_not_index”. If it exists, it outputs the script necessary to inform search spiders not to index this page. And from now on whenever you want to disable indexing for a specific post, simply use the custom field “do_not_index” with a dummy value in the WordPress editor to trigger the above code.

Keep in mind that this will only work for those spiders that respect the “noindex” tag. This will include all of the major reputable search engines, so you’re mostly covered. There are plenty of badly behaved spiders and bots out that that happily ignore noindex instructions, but there’s very little you can do about that short of identifying and blocking them from your site outright.

Leave a Reply

Your email address will not be published. Required fields are marked *