Make WordPress Core

Opened 5 weeks ago

Last modified 2 weeks ago

#61436 new defect (bug)

'src' not in $attr for wp_get_loading_optimization_attributes

Reported by: prestonwordsworth's profile prestonwordsworth Owned by:
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.4
Component: Media Keywords: has-patch has-unit-tests
Focuses: performance Cc:


The relevant dev note has the following snippet:

function set_fetchpriority_high_on_specific_image( $loading_attrs, $tag_name, $attr, $context ) {
    if ( 'img' === $tag_name ) {
        if (
            'the_content' === $context &&
            isset( $attr['src'] ) &&
            $attr['src'] === ''
        ) {
            $loading_attrs['fetchpriority'] = 'high';
        } else {
            unset( $loading_attrs['fetchpriority'] );
    return $loading_attrs;

'src', however, hasn’t made it into $attr array yet:

        $optimization_attrs = wp_get_loading_optimization_attributes(
                        'width'         => $width,
                        'height'        => $height,
                        'loading'       => $loading_val,
                        'fetchpriority' => $fetchpriority_val,
                        'decoding'      => $decoding_val,

Change History (9)

#1 @joemcgill
5 weeks ago

  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 6.5.4 to 6.4

Hi @prestonwordsworth, welcome to Trac!

The main place where attributes are set up for this filter are in wp_img_tag_add_loading_optimization_attrs(), which does not pass the src nor the actual image to wp_get_loading_optimization_attributes() where the filter is called. There are other places where the src is passed, like in get_header_image_tag() or WP_Widget_Media_Image::render_media, but it probably makes sense to make this consistent.

Thanks for the report!

#2 @prestonwordsworth
5 weeks ago

Many thanks for confirming that this is a case, @joemcgill!

So is it currently possible to change the fetchpriority or decoding of a specific image using a filter?

This ticket was mentioned in PR #6830 on WordPress/wordpress-develop by @deepakrohilla.

5 weeks ago

  • Keywords has-patch added

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.

2 weeks ago

#5 @adamsilverstein
2 weeks ago

  • Keywords needs-unit-tests added

#6 @adamsilverstein
2 weeks ago

A unit test to validate would be nice to have

#7 @joemcgill
2 weeks ago

  • Focuses docs removed
  • Milestone changed from Future Release to 6.7

Thanks for the PR, @deepakrohilla! This looks pretty good. I'm going to add this to the 6.7 milestone and get a proper code review. It will be great to add unit tests for this.

This ticket was mentioned in PR #6967 on WordPress/wordpress-develop by @narenin.

2 weeks ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Trac ticket:

#9 @deepakrohilla
2 weeks ago

Thanks @joemcgill I have added test cases in PR ,Please review 

Note: See TracTickets for help on using tickets.