Skip to content

Instantly share code, notes, and snippets.

@adamrosloniec
Last active August 9, 2019 01:42
Show Gist options
  • Save adamrosloniec/c8d7264dc228bec78c538653c0166679 to your computer and use it in GitHub Desktop.
Save adamrosloniec/c8d7264dc228bec78c538653c0166679 to your computer and use it in GitHub Desktop.
WordPress - Automatically disallow indexing on staging sites
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