Check if website is visible to search engines

smartsovereign
18 May 2022

It’s easy to forget to turn indexing back on after you’ve finished developing a site, this snippet will remind you. No extra plugins are necessary. This should be a part of every template you have.

Load this in the admin area only.

<?php

/**
 * Check if Website is visible to Search Engines
 */
function wpse_check_visibility() {
    if ( ! class_exists( 'WPSEO_Admin' ) ) {
        if ( '0' == get_option( 'blog_public' ) ) {
            add_action( 'admin_footer', 'wpse_private_wp_warning' );
        }
    }
}
add_action( 'admin_init', 'wpse_check_visibility' );

/**
 * If website is Private, show alert
 */
function wpse_private_wp_warning() {
    if ( ( function_exists( 'is_network_admin' ) && is_network_admin() ) ) {
        return;
    }

    echo '<div id="robotsmessage" class="error">';
    echo '<p><strong>' . __( 'Huge SEO Issue: You\'re blocking access to robots.', 'wpse-seo' ) . '</strong> ' . sprintf( __( 'You must %sgo to your Reading Settings%s and uncheck the box for Search Engine Visibility.', 'wordpress-seo' ), '<a href="' . esc_url( admin_url( 'options-reading.php' ) ) . '">', '</a>' ) . '</p></div>';
}

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy