WordPress has a checkbox under Settings → Reading called “Discourage search engines from indexing this site”. You tick it while a site is in development and forget it at launch, and the site stays out of Google for weeks. WordPress itself only mentions it in small print in the At a Glance widget.
This snippet shows a red notice at the top of every wp-admin screen while search engines are blocked, with a link to the setting. Only administrators see it, and it disappears as soon as the box is unticked.
The snippet
<?php
/**
* Warn administrators on every wp-admin screen while
* "Discourage search engines from indexing this site" is ticked.
*/
add_action( 'admin_notices', 'dpc_search_visibility_notice' );
function dpc_search_visibility_notice() {
if ( '0' !== (string) get_option( 'blog_public' ) || ! current_user_can( 'manage_options' ) || is_network_admin() ) {
return;
}
// Yoast SEO already shows its own warning for this.
if ( class_exists( 'WPSEO_Admin' ) ) {
return;
}
$link = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( admin_url( 'options-reading.php' ) ),
esc_html__( 'Settings → Reading', 'dpc' )
);
printf(
'<div class="notice notice-error dpc-search-visibility"><p><strong>%1$s</strong> %2$s</p></div>',
esc_html__( 'Search engines are blocked on this site.', 'dpc' ),
sprintf(
/* translators: %s: link to Settings → Reading. */
esc_html__( 'Untick "Discourage search engines from indexing this site" in %s when the site goes live.', 'dpc' ),
$link // Escaped above.
)
);
}
Add it with Scripts Organizer
In Scripts Organizer go to Code Blocks → Add New and give the block a name. Set Trigger location to Admin only, tick PHP under Script location, paste the code into the PHP editor and publish. Leave Action/Hook empty. Admin only fits: the notice only exists in wp-admin, so the code is not loaded on the front end at all.
The same code also works unchanged in a small plugin or an mu-plugin.
How it works
- The setting is stored in the
blog_publicoption:1allows indexing,0discourages it. The snippet only shows the notice for0. - It uses the
admin_noticeshook and the corenotice notice-errorclasses, so the warning appears in the usual place below the page title. The earlier version printed it onadmin_footer, at the bottom of the page. - Only users with
manage_optionssee it, because only they can change the setting, and it is skipped in the network admin. - All text goes through
esc_html__()and the link throughesc_url(). The earlier version printed translated strings unescaped. - When Yoast SEO is active, the snippet stays quiet, because Yoast shows its own warning for the same setting.
Customise it
- Show it to editors as well: replace
manage_optionswithedit_others_posts. - Only on the dashboard: add
if ( 'dashboard' !== get_current_screen()->id ) { return; }at the top of the function.
Gotchas
- Unticking the box only removes the
noindexsignal. Some hosts block search engines on staging domains on their own, withrobots.txtor HTTP headers; check those too after launch. - On a site that should stay hidden (staging, intranet), disable the code block, otherwise the notice is always there.
- A password-protected or maintenance-mode site is hidden from search engines for other reasons; this notice does not check those.
In the Scripts Organizer library Import it with one click from Scripts Organizer.