# Noindex Subsites With a Staging Path

> Adds a noindex robots directive to any subsite whose address contains "staging", "dev" or "test", so preview copies inside a network never show up in search results.

- Type: PHP
- Runs: Run everywhere
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: seo, staging, noindex
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-staging-subsites-noindex/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

$wpide_markers = array( 'staging', 'dev', 'test' ); // Words that mark a preview site.

$wpide_site = get_site();
$wpide_addr = $wpide_site ? strtolower( $wpide_site->domain . $wpide_site->path ) : '';
$wpide_hit  = false;

foreach ( $wpide_markers as $wpide_marker ) {
    if ( preg_match( '/(^|[.\/-])' . preg_quote( $wpide_marker, '/' ) . '([.\/-]|$)/', $wpide_addr ) ) {
        $wpide_hit = true;
        break;
    }
}

if ( ! $wpide_hit ) {
    return;
}

add_filter( 'wp_robots', 'wp_robots_no_robots' );
add_filter( 'robots_txt', function () {
    return "User-agent: *\nDisallow: /\n";
}, 99 );
```

## Notes

Edit $wpide_markers to match how you name preview sites.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Noindex Subsites With a Staging Path" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
