Make WordPress Core


Ignore:
Timestamp:
07/11/2023 01:56:55 PM (14 months ago)
Author:
joemcgill
Message:

Media: Optimize images created in shortcodes.

This fixes an issue where images dynamically created during shortcode rendering (e.g., shortcode image galleries), were not getting image optimizations like loading="lazy" or fetchpriority="hight" applied. Note that even after this commit, shortcodes are processed after the main content images, which can affect the order in which optimizations are applied in content areas.

Follow-up to [56037].

Props spacedmonkey, flixos90, thekt12, swissspidy, joemcgill.
Fixes #58681.

File:
1 edited

Legend:

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

    r56191 r56214  
    57265726    /*
    57275727     * The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
    5728      * as they are likely above the fold.
    5729      */
    5730     if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) {
     5728     * as they are likely above the fold. Shortcodes are processed after content images, so if
     5729     * thresholds haven't already been met, apply the same logic to those as well.
     5730     */
     5731    if ( 'the_content' === $context || 'the_post_thumbnail' === $context || 'do_shortcode' === $context ) {
    57315732        // Only elements within the main query loop have special handling.
    57325733        if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
Note: See TracChangeset for help on using the changeset viewer.