wp_robots_noindex_search( array $robots ): array

Adds noindex to the robots meta tag if a search is being performed.

Description

If a search is being performed then noindex will be output to tell web robots not to index the page content. Add this to the ‘wp_robots’ filter.

Typical usage is as a ‘wp_robots’ callback:

add_filter( 'wp_robots', 'wp_robots_noindex_search' );

See also

Parameters

$robotsarrayrequired
Associative array of robots directives.

Return

array Filtered robots directives.

Source

function wp_robots_noindex_search( array $robots ) {
	if ( is_search() ) {
		return wp_robots_no_robots( $robots );
	}

	return $robots;
}

Changelog

VersionDescription
5.7.0Introduced.

User Contributed Notes

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