Preventing Search Engines From Indexing All Posts

- 1 answer

I'm working on a Wordpress site where I'm using the posts to create a list of tour dates for an entertainer. With ACF I have fields set up in a table and the client just enters a date, location, link to buy tickets, etc.

The table is all I need visitors to see. The actual post created by single.php is not going to be styled and should never be seen.

I want to prevent someone searching the artist and city and coming across the post.

Is there a plugin or a disallow I can put in the robot.txt file?

Any help is appreciated. Kinda funny in a time where everyone is trying to get noticed by search engines and I want to hide something from them!



Add the code below to your themes functions.php:

add_action('wp_head', 'your_prefix_noindex_nofollow');
function your_prefix_noindex_nofollow() {  
      echo '<meta name="robots" content="noindex,nofollow"/>';

You can also change "your_prefix" in the function name to whatever you like. It will work as is, but it's a good practice to use the same prefix in all your function names.