# wp_robots()

URL: https://chugunov.pro/api-wordpress/functions/wp_robots/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.7.0.

## Сигнатура

```php
wp_robots()
```

## Описание

Собирает директивы robots для текущего контекста, используя фильтр 'wp_robots'. Затем директивы очищаются, и мета-тег robots выводится, если есть хотя бы одна подходящая директива.

## Исходный код

Файл: `wp-includes/robots-template.php:20`

```php
function wp_robots() {
	/**
	 * Filters the directives to be included in the 'robots' meta tag.
	 *
	 * The meta tag will only be included as necessary.
	 *
	 * @since 5.7.0
	 *
	 * @param array $robots Associative array of directives. Every key must be the name of the directive, and the
	 *                      corresponding value must either be a string to provide as value for the directive or a
	 *                      boolean `true` if it is a boolean directive, i.e. without a value.
	 */
	$robots = apply_filters( 'wp_robots', array() );

	$robots_strings = array();
	foreach ( $robots as $directive => $value ) {
		if ( is_string( $value ) ) {
			// If a string value, include it as value for the directive.
			$robots_strings[] = "{$directive}:{$value}";
		} elseif ( $value ) {
			// Otherwise, include the directive if it is truthy.
			$robots_strings[] = $directive;
		}
	}

	if ( empty( $robots_strings ) ) {
		return;
	}

	echo "<meta name='robots' content='" . esc_attr( implode( ', ', $robots_strings ) ) . "' />\n";
}
```

## История изменений

- 5.7.1 — No longer prevents specific directives to occur together.
- 5.7.0 — Introduced.

## Связанные

Использует: [`esc_attr`](https://chugunov.pro/api-wordpress/functions/esc_attr/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`_default_wp_die_handler`](https://chugunov.pro/api-wordpress/functions/_default_wp_die_handler/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_robots/
