Make WordPress Core

Changeset 35358


Ignore:
Timestamp:
10/22/2015 07:30:12 PM (9 years ago)
Author:
azaozz
Message:

Responsive Images: limit the size of images included in srcset attributes. Introduce max_srcset_image_width filter to adjust the limit.

Props joemcgill.
Fixes #34341.

File:
1 edited

Legend:

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

    r35355 r35358  
    929929    $img_edited = preg_match( '/-e[0-9]{13}/', $img_url, $img_edit_hash );
    930930
     931    /**
     932     * Filter the maximum width included in a srcset attribute.
     933     *
     934     * @since 4.4.0
     935     *
     936     * @param array|string $size Size of image, either array or string.
     937     */
     938    $max_srcset_width = apply_filters( 'max_srcset_image_width', 1600, $size );
     939
    931940    /*
    932941     * Set up arrays to hold url candidates and matched image sources so
     
    944953        if ( $img_edited && ! strpos( $img['file'], $img_edit_hash[0] ) ) {
    945954            continue;
     955        }
     956
     957        // Filter out images that are wider than $max_srcset_width.
     958        if ( $max_srcset_width && $img['width'] > $max_srcset_width ) {
     959            $contiue;
    946960        }
    947961
Note: See TracChangeset for help on using the changeset viewer.