As we all know, we can do website SEO with the plugin of WordPress.
But what if we don’t want to insert any plugins into the website?
Here, we will see how we can prevent the indexing of a draft single post page without the plugin.
Open the active theme’s header.php file.
Insert the below code into the head tag of header.php.
<?php if(is_single()) { if( get_post_status() == 'draft' ) { ?> <meta name="robots" content="noindex, follow"> <?php } } ?>
We can modify the above code per our required post type or status.
Review the screenshots below of draft and published posts.
1. Post status: Draft
2. Post status: Publish
If you face any issues, please mention them in the comments below.