Noindex Staging and Development Sites
Adds noindex, nofollow to every page when WP_ENVIRONMENT_TYPE is not production, so staging copies never end up in search results.
Opens WPIDE on
Code
add_filter( 'wp_robots', function ( $robots ) {
if ( function_exists( 'wp_get_environment_type' ) && 'production' !== wp_get_environment_type() ) {
$robots['noindex'] = true;
$robots['nofollow'] = true;
}
return $robots;
} );
Notes
Set define( 'WP_ENVIRONMENT_TYPE', 'staging' ); in wp-config.php on staging copies.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.