Created
December 22, 2025 03:56
-
-
Save petertwise/347fc5507fcb072181f9d72c1823edab to your computer and use it in GitHub Desktop.
Square Candy noindex Staging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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