1. 首页
  2. WordPress 函数手册

do_robots()

do_robots()

显示默认值robots.txt文件文件内容。
Displays the default robots.txt file content.

目录锚点:#返回#源码


返回(Return)

无返回值


源码(Source)

/**
 * Display the robots.txt file content.
 *
 * The echo content should be with usage of the permalinks or for creating the
 * robots.txt file.
 *
 * @since 2.1.0
 */
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: *
";
	$public = get_option( 'blog_public' );
	if ( '0' == $public ) {
		$output .= "Disallow: /
";
	} else {
		$site_url = parse_url( site_url() );
		$path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
		$output .= "Disallow: $path/wp-admin/
";
	}

	/**
	 * Filter the robots.txt output.
	 *
	 * @since 3.0.0
	 *
	 * @param string $output Robots.txt output.
	 * @param bool   $public Whether the site is considered "public".
	 */
	echo apply_filters( 'robots_txt', $output, $public );
}
更新版本 源码位置 使用 被使用
5.3.0 wp-includes/functions.php:1628 0 6

do_robots() 为WP2原创文章,链接:https://www.wp2.cn/functions/do_robots-2/

发表评论

您的电子邮箱地址不会被公开。