apply_filters( 'wp_robots', array $robots )

Filters the directives to be included in the ‘robots’ meta tag.


Description Description

The meta tag will only be included as necessary.


Top ↑

Parameters Parameters

$robots

(array) 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.


Top ↑

Source Source

File: wp-includes/robots-template.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
5.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by jakeparis

    Example of adding a noindex robots tag.

    add_filter( 'wp_robots', function( $robots ) {
    	$robots['noindex'] = true;
    
    	return $robots;
    } );
    

    To affect pages with a certain page template, you can add this directly to the template, as long as it’s above the call to wp_header().

    To have more granular control over what pages are affected, you can add the snippet to your functions.php file and work with the current page inside the function:

    add_filter( 'wp_robots', function( $robots ) {
    	$id = get_the_ID();
    
    	if ( 19 === $id ) {
    		$robots['noindex'] = true;
    	}
    
    	return $robots;
    } );
    

You must log in before being able to contribute a note or feedback.