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.
<?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.