General: Add `noindex` robots meta tag to search results.
Prevent search engines indexing internal search results to protect against reflected web spam attacks. Props abagtcs, audrasjb, ayeshrajans, burtrw, johnbillion, jonoaldersonwp, peterwilsoncc, poena, sabernhardt, xkon. Fixes #52457 Built from https://develop.svn.wordpress.org/trunk@50370 git-svn-id: http://core.svn.wordpress.org/trunk@49981 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a4493bf242
commit
b51a707468
|
@ -238,6 +238,7 @@ add_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
|
|||
|
||||
// Robots filters.
|
||||
add_filter( 'wp_robots', 'wp_robots_noindex' );
|
||||
add_filter( 'wp_robots', 'wp_robots_noindex_search' );
|
||||
add_filter( 'wp_robots', 'wp_robots_max_image_preview_large' );
|
||||
|
||||
// Mark site as no longer fresh.
|
||||
|
|
|
@ -87,6 +87,31 @@ function wp_robots_noindex( array $robots ) {
|
|||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds noindex to the robots meta tag if a search is being performed.
|
||||
*
|
||||
* 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
|
||||
* {@see 'wp_robots'} filter.
|
||||
*
|
||||
* Typical usage is as a {@see 'wp_robots'} callback:
|
||||
*
|
||||
* add_filter( 'wp_robots', 'wp_robots_noindex_search' );
|
||||
*
|
||||
* @since 5.7.0
|
||||
* @see wp_robots_no_robots()
|
||||
*
|
||||
* @param array $robots Associative array of robots directives.
|
||||
* @return array Filtered robots directives.
|
||||
*/
|
||||
function wp_robots_noindex_search( array $robots ) {
|
||||
if ( is_search() ) {
|
||||
return wp_robots_no_robots( $robots );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds noindex to the robots meta tag.
|
||||
*
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.7-beta3-50369';
|
||||
$wp_version = '5.7-beta3-50370';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue