Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
Last active January 15, 2016 05:24
Show Gist options
  • Save BronsonQuick/c9040d4187ae93c09eac to your computer and use it in GitHub Desktop.
Save BronsonQuick/c9040d4187ae93c09eac to your computer and use it in GitHub Desktop.
Don't index WP sites with staging in the URL.
<?php
/*
Plugin Name: United Influencers Stop Indexing On Staging
Plugin URI: https://hmn.md/
Description: This plugin prevents search engines from indexing our staging sites.
Author: Human Made Limited
Version: 0.1
Author URI: https://hmn.md/
*/
namespace United_Bloggers\Stop_Indexing_On_Staging;
/**
* Make sure the top level domain and subdomains are never indexed.
*
* @return string
*/
function stop_indexing( $blog_public_option ) {
$server_name = $_SERVER['HTTP_HOST'];
if ( strpos( $server_name, 'staging.' ) !== false ) {
return '0';
}
return $blog_public_option;
}
add_filter( 'pre_option_blog_public', __NAMESPACE__ . '\\stop_indexing' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment