do_robots()

Display the robots.txt file content.


Description

The echo content should be with usage of the permalinks or for creating the robots.txt file.


Source

File: wp-includes/functions.php

function do_robots() {
	header( 'Content-Type: text/plain; charset=utf-8' );

	/**
	 * Fires when displaying the robots.txt file.
	 *
	 * @since WP-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 WP-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 );
}


Changelog

Changelog
Version Description
WP-5.3.0 Remove the "Disallow: /" output if search engine visiblity is discouraged in favor of robots meta HTML tag in wp_no_robots().
WP-2.1.0 Introduced.