WordPress中如何设置robots文件

了解robots

网站robots文件-一个博客
网站robots文件-一个博客
22年5月1日 16:09
0240

WordPress中的robots

如果您目的是屏蔽所有搜索引擎“蜘蛛”爬取你的网站,可以使用wp自带的设置,在设置>阅读中:

搜索引擎在访问网站时,会先查看网站根目录下是否存在robots.txt文件,robots文件用来指定搜索引擎禁止抓取或允许抓取某些内容。但是wordpress默认的robots文件是在wp-includes目录下的functions.php文件中设置的

/**
 * Displays the default robots.txt file content.
 *
 * @since 2.1.0
 * @since 5.3.0 Remove the "Disallow: /" output if search engine visiblity is
 *              discouraged in favor of robots meta HTML tag via wp_robots_no_robots()
 *              filter callback.
 */
function do_robots() {
 header( 'Content-Type: text/plain; charset=utf-8' );

 /**
  * Fires when displaying the robots.txt file.
  *
  * @since 2.1.0
  */
 do_action( 'do_robotstxt' );

 $output = "User-agent: *\n";
 $public = get_option( 'blog_public' );

 $site_url = parse_url( site_url() );
 $path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
 $output  .= "Disallow: $path/wp-admin/\n";
 $output  .= "Allow: $path/wp-admin/admin-ajax.php\n";

 /**
  * Filters the robots.txt output.
  *
  * @since 3.0.0
  *
  * @param string $output The robots.txt output.
  * @param bool   $public Whether the site is considered "public".
  */
 echo apply_filters( 'robots_txt', $output, $public );
}

你可以使用wordpress默认的robots文件设置,针对自己网站的情况做相应的更改;也可以自己写一个robots.txt,放在网站根目录下,那么wordpress将优先使用你在根目录下设置的robots文件

关于怎么设置robots文件可以参考上面的文章。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
留言 抢沙发
头像
来都来了,不说两句?
提交
头像

昵称

取消
昵称表情代码图片

    请登录后查看评论内容