Robots: Add `max-image-preview:large` directive by default.

This changeset introduces a `wp_robots_max_image_preview_large()` function which is hooked into the `wp_robots` filter to include the `max-image-preview:large` directive for all sites which are configured to be indexed by search engines. The directive allows search engines to display large image previews for the site in search results.

Props adamsilverstein, Clorith, flixos90, helen, joostdevalk, tweetythierry, westonruter.
Fixes #51511.

Built from https://develop.svn.wordpress.org/trunk@50078


git-svn-id: http://core.svn.wordpress.org/trunk@49778 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2021-01-29 20:38:03 +00:00
parent eac269decd
commit 8aacac3486
3 changed files with 24 additions and 1 deletions

View File

@ -233,6 +233,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_max_image_preview_large' );
// Mark site as no longer fresh.
foreach ( array( 'publish_post', 'publish_page', 'wp_ajax_save-widget', 'wp_ajax_widgets-order', 'customize_save_after' ) as $action ) {

View File

@ -133,3 +133,25 @@ function wp_robots_sensitive_page( array $robots ) {
$robots['noarchive'] = true;
return $robots;
}
/**
* Adds 'max-image-preview:large' to the robots meta tag.
*
* This directive tells web robots that large image previews are allowed to be
* displayed, e.g. in search engines, unless the blog is marked as not being public.
*
* Typical usage is as a {@see 'wp_robots'} callback:
*
* add_filter( 'wp_robots', 'wp_robots_max_image_preview_large' );
*
* @since 5.7.0
*
* @param array $robots Associative array of robots directives.
* @return array Filtered robots directives.
*/
function wp_robots_max_image_preview_large( array $robots ) {
if ( get_option( 'blog_public' ) ) {
$robots['max-image-preview'] = 'large';
}
return $robots;
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-alpha-50077';
$wp_version = '5.7-alpha-50078';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.