WordPress at a glance

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;
$wp_query->is_robots();

No Hooks.

Return

true/false.

Usage

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

Code of is robots: wp-includes/query.php VER 5.1.1

<?php
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();
}

Related Functions

From tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Main Query

No comments
    Hello, !     Log In . Register