admin管理员组文章数量:1322850
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 badges4 Answers
Reset to default 4The 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
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.
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.)
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 } ?>
本文标签: Check if Website is hidden from Search Engines
版权声明:本文标题:Check if Website is hidden from Search Engines? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742113317a2421353.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论