最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Check if Website is hidden from Search Engines?

programmeradmin5浏览0评论

Any idea how to check if the website is hidden from search engines? The reason is I want to show a big red banner at the top of the homepage when this option is checked because I always forget that this option is checked.

Any idea how to check if the website is hidden from search engines? The reason is I want to show a big red banner at the top of the homepage when this option is checked because I always forget that this option is checked.

Share Improve this question edited Mar 30, 2016 at 17:05 herrfischer asked Mar 30, 2016 at 16:25 herrfischerherrfischer 2274 silver badges13 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 4

The setting is stored in the option blog_public.

if( 0 == get_option( 'blog_public' ) ){
    echo 'search engines discouraged';
}

Pretty sure I stole borrowed the following piece of code from the very handy and useful Yoast Plugin:

/**
 * 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>';
}

Pretty much on admin_init we check if our site is private. If it is we're going to use the footer and WordPress alert styles to tell us that the site is private. The WPSEO_Admin is Yoast as I believe they will also tell you the site is private if it's installed so we don't want to step on their toes.

Another way to see if your Website is hidden from Search Engines is going to Settings » Privacy Settings

The Site Privacy setting controls who can view your site, allowing you to make the site private or public. To access this setting, go to My Site → Settings and look for Privacy.

Privacy Options

  1. Public: This is the setting used by most sites. It allows everyone to read your site and enables your site to be included in search engine results and other content sites.

  2. Hidden: If you want all human visitors to be able to read your blog, but want to block web crawlers for search engines, this is the setting for you. (Please note, however, that not all search engines respect this setting.)

  3. Private: Select this option to make your site private. If you want specific people to be able to view it (and add comments, if you’ve enabled them), you’ll need to invite them to be a viewer.

Using this since Milos answer on every WordPress project as a handy snippet (put it right after the opening body tag):

<?php if ( is_user_logged_in() ) { ?>
    <style>
        a.searchengines_blocked {
            position: fixed;
            bottom: 0;
            left: 0;
            z-index: 99999;
            color: black !important;
            background-color: #ffcd1b !important;
            font-weight: normal;
            font-size: 1.8rem;
            padding: 6px 15px;
            text-align: center;
            vertical-align: middle;
            border-top-right-radius: 10px;
        }
    </style>
    <?php
        if( 0 == get_option( 'blog_public' ) ){
            echo '<a href="./wp-admin/options-reading.php" class="searchengines_blocked">!G</a>';
        }
    ?>
<?php } ?>
发布评论

评论列表(0)

  1. 暂无评论