Skip to content

Instantly share code, notes, and snippets.

@petertwise
Created December 22, 2025 03:56
Show Gist options
  • Select an option

  • Save petertwise/347fc5507fcb072181f9d72c1823edab to your computer and use it in GitHub Desktop.

Select an option

Save petertwise/347fc5507fcb072181f9d72c1823edab to your computer and use it in GitHub Desktop.
Square Candy noindex Staging
<?php
/*
Plugin Name: Square Candy noindex Staging
Description: A must-use plugin to add noindex to staging sites.
Author: squarecandy
Author URI: https://squarecandydesign.com
Version: 1.0
License: GPL2
SETUP INSTRUCTIONS:
1. Install this plugin in the mu-plugins directory.
2. Add the following to your wp-config.php file:
define( 'WP_ENVIRONMENT_TYPE', 'staging' );
or
define( 'WP_ENVIRONMENT_TYPE', 'development' );
3. Use an incognito/private browser window and view source on the site. Confirm that the noindex meta tag is present.
*/
// if WP_ENVIRONMENT_TYPE is defined and set to 'development' or 'staging'
if ( defined( 'WP_ENVIRONMENT_TYPE' ) && ( 'development' === WP_ENVIRONMENT_TYPE || 'staging' === WP_ENVIRONMENT_TYPE ) ) :
// enforce noindex/nofollow on staging/development sites
add_filter( 'wp_robots', 'squarecandy_noindex_staging', PHP_INT_MAX ); // use PHP_INT_MAX to be extra sure we override all SEO plugins, etc.
function squarecandy_noindex_staging( $robots ) {
$robots = array(); // clear any existing values
$robots['noindex'] = true;
$robots['nofollow'] = true;
return $robots;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment