1. 首页
  2. WordPress钩子手册

do_robots

do_action( ‘do_robots’ )

动作钩子::当模板加载器确定robots.txt文件请求。
Action Hook: Fired when the template loader determines a robots.txt request.

目录锚点:#源码


源码(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 );
}
更新版本 源码位置 使用 被使用
2.1.0 wp-includes/template-loader.php:37 0 0

do_robots 为WP2原创文章,链接:https://www.wp2.cn/hook/do_robots/