WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/29/2021 08:36:03 PM (10 months ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/robots-template.php

    r49992 r50078  
    134134    return $robots;
    135135}
     136
     137/**
     138 * Adds 'max-image-preview:large' to the robots meta tag.
     139 *
     140 * This directive tells web robots that large image previews are allowed to be
     141 * displayed, e.g. in search engines, unless the blog is marked as not being public.
     142 *
     143 * Typical usage is as a {@see 'wp_robots'} callback:
     144 *
     145 *     add_filter( 'wp_robots', 'wp_robots_max_image_preview_large' );
     146 *
     147 * @since 5.7.0
     148 *
     149 * @param array $robots Associative array of robots directives.
     150 * @return array Filtered robots directives.
     151 */
     152function wp_robots_max_image_preview_large( array $robots ) {
     153    if ( get_option( 'blog_public' ) ) {
     154        $robots['max-image-preview'] = 'large';
     155    }
     156    return $robots;
     157}
Note: See TracChangeset for help on using the changeset viewer.