WordPress at Your Fingertips

is_robots() WP 2.1.0

Checks if this is a request to robots.txt file. A conditional tag.

If there is no robots.txt file in the site root directory, WordPress generates the content of this file on the fly, and this conditional tag return true.

For such request (to robots.txt that doesn't physically exist) WordPress trigger an action:

do_action( 'do_robots' );

This function is a wrapper for this code:

global $wp_query;
1 time — 0.000014 sec (very fast) | 50000 times — 0.02 sec (speed of light) | PHP 7.1.2, WP 4.7.3

No Hooks.


true|false. Whether the query is for the robots.txt file.


if( is_robots() ){
	// this is robots.txt file


  • Global. WP_Query. $wp_query WordPress Query object.


Since 2.1.0 Introduced.

Code of is_robots() WP 5.8

function is_robots() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;

	return $wp_query->is_robots();

From tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Main Query

No comments
    Log In