Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Keep staging sites out of search engines

On staging, development and local copies of the site, every page tells search engines not to index it. The live site isn’t touched.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category SEO
  • Tested with WordPress 7.1
PHP
<?php

add_filter(
	'wp_robots',
	static function ( $robots ) {
		if ( 'production' !== wp_get_environment_type() ) {
			$robots['noindex']  = true;
			$robots['nofollow'] = true;
		}
		return $robots;
	}
);

Good to know

Needs WP_ENVIRONMENT_TYPE set on the staging copy (many hosts do it). A password on the staging site is safer still.

In these packs

  • Login and security extras: Limit login attempts, email-only logins, a registration spam trap and more hardening.
  • SEO basics: Meta descriptions, social sharing tags, article structured data and cleaner indexing, for sites without an SEO plugin.
  • Developer tools: Maintenance mode, template names, page stats, environment labels and a WP-Cron viewer.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.