Last active
August 9, 2019 01:42
-
-
Save adamrosloniec/c8d7264dc228bec78c538653c0166679 to your computer and use it in GitHub Desktop.
WordPress - Automatically disallow indexing on staging sites
This file contains 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
function theme_disallow_indexing_for_staging() { | |
if ( | |
str_ireplace(array('staging-subdomain-1.com', 'dev-subdomain-2.net'), '', $_SERVER['SERVER_NAME']) != $_SERVER['SERVER_NAME'] | |
&& get_option('blog_public') == '1' | |
) { | |
add_action('pre_option_blog_public', '__return_zero'); | |
} | |
} | |
add_action('init', 'theme_disallow_indexing_for_staging'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment