Skip to content

Modern Image Formats - wp_calculate_image_srcset => false => no SOURCE element #2191

Closed

Description

@1ucay

I found that if you turn off srcset, the source element with AVIF is not added to the image.

AVIF - Generate images in this format
✓ Also generate fallback images in the original upload format
✓ Generate all fallback image sizes including custom sizes
✓ Use < picture > Element (experimental)

add_filter( 'wp_calculate_image_srcset', '__return_false' );

is this proper behavior?

Activity

  1. moved this to Not Started/Backlog 📆 in WP Performance Ongoingon Sep 26, 2025
  2. adamsilverstein commented on Sep 26, 2025

    @adamsilverstein
    Member

    Hi @1ucay - thanks for the bug report.

    is this proper behavior?

    Sounds like a bug.

    What happens if you turn off the Use < picture > Element (experimental) option?

  3. b1ink0 commented on Oct 8, 2025

    @b1ink0
    Contributor

    Hmm, I’m not able to replicate the bug, but with the wp_calculate_image_srcset filter returning false, the <img> tag only has the src attribute with the fallback JPG image, and the <source> tag is generated with only one src in the srcset. See below:

    <picture class="wp-picture-11" style="display: contents"
      ><source
        type="image/webp"
        srcset="
          http://localhost:8888/wp-content/uploads/2025/10/10000x10000-1024x1024-jpg.webp
        " />
      <img
        data-od-unknown-tag=""
        data-od-xpath="/HTML/BODY/DIV[@class='wp-site-blocks']/*[2][self::MAIN]/*[1][self::DIV]/*[2][self::DIV]/*[6][self::FIGURE]/*[1][self::PICTURE]/*[2][self::IMG]"
        data-dominant-color="4d4d4d"
        data-has-transparency="false"
        style="--dominant-color: #4d4d4d"
        fetchpriority="high"
        decoding="async"
        width="1024"
        height="1024"
        sizes="(max-width: 645px) 100vw, 645px"
        src="http://localhost:8888/wp-content/uploads/2025/10/10000x10000-1024x1024.jpg"
        alt=""
        class="wp-image-11 not-transparent"
    /></picture>

    When the Use <picture> Element (experimental) option is disabled, this is what gets generated the <img> tag has the src with the selected modern image format.

    <figure class="wp-block-image size-large">
      <img
        data-od-unknown-tag=""
        data-od-xpath="/HTML/BODY/DIV[@class='wp-site-blocks']/*[2][self::MAIN]/*[1][self::DIV]/*[2][self::DIV]/*[6][self::FIGURE]/*[1][self::IMG]"
        data-dominant-color="4d4d4d"
        data-has-transparency="false"
        style="--dominant-color: #4d4d4d"
        fetchpriority="high"
        decoding="async"
        width="1024"
        height="1024"
        sizes="(max-width: 645px) 100vw, 645px"
        src="http://localhost:8888/wp-content/uploads/2025/10/10000x10000-1024x1024-jpg.webp"
        alt=""
        class="wp-image-11 not-transparent"
      />
    </figure>

    This issue is probably handled by the following else logic:

    // Gets the srcset and sizes from the IMG tag.
    $sizes = $processor->get_attribute( 'sizes' );
    $srcset = $processor->get_attribute( 'srcset' );
    if ( null !== $srcset && null !== $sizes ) {

    When the wp_calculate_image_srcset filter returns false, the srcset is null.

    .
    .
    .

    } else {
    foreach ( $mime_types as $image_mime_type ) {
    $image_srcset = webp_uploads_get_mime_type_image( $attachment_id, $src, $image_mime_type );
    if ( is_string( $image_srcset ) ) {
    $picture_sources .= sprintf(
    '<source type="%s" srcset="%s">',
    esc_attr( $image_mime_type ),
    esc_attr( $image_srcset )
    );
    }
    }
    }

    I believe this is the correct behavior, but I want other contributors to try to replicate it, I might be missing something.

    cc: @adamsilverstein

  4. 1ucay commented on Oct 30, 2025

    @1ucay
    Author

    I have to apologize to you all, it works fine with the filter.

    add_filter( 'wp_calculate_image_srcset', '__return_false' );
    <picture class="wp-picture-698" style="display: contents"
      ><source
        type="image/avif"
        srcset="
          /content/uploads/2025/08/generated-thumb-1756510127-400x225-jpg.avif
        " />
      <img
        width="400"
        height="225"
        src="/content/uploads/2025/08/generated-thumb-1756510127-400x225.jpg"
        class="attachment-wide-sm size-wide-sm not-transparent"
        alt="Ut dolor ea nisi do"
        fetchpriority="low"
        decoding="async"
        data-has-transparency="false"
        data-dominant-color="73bbd4"
        style="--dominant-color: #73bbd4"
    /></picture>
  5. adamsilverstein commented on Nov 17, 2025

    @adamsilverstein
    Member

    Thanks @1ucay - closing as this turned out to not be a bug.

  6. moved this from Not Started/Backlog 📆 to Done 😃 in WP Performance Ongoingon Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature is broken

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions