显示robots.txt文件内容。

原型

do_robots()

描述

回显内容应该与永久链接的使用或创建robots.txt文件。

源文件

路径:wp-includes/functions.php

<?php
...
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' );
	if ( '0' == $public ) {
		$output .= "Disallow: /n";
	} else {
		$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.phpn";
	}
	/**
	 * Filters 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 );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/do_robots/