#61436 closed defect (bug) (fixed)
'src' not in $attr for wp_get_loading_optimization_attributes
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.7 | Priority: | normal |
| Severity: | normal | Version: | 6.4 |
| Component: | Media | Keywords: | has-patch has-unit-tests |
| Focuses: | performance | Cc: |
Description
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'] === 'https://example.org/a-specific-image.jpg'
) {
$loading_attrs['fetchpriority'] = 'high';
} else {
unset( $loading_attrs['fetchpriority'] );
}
}
return $loading_attrs;
}
add_filter(
'wp_get_loading_optimization_attributes',
'set_fetchpriority_high_on_specific_image',
10,
4
);
'src', however, hasn’t made it into $attr array yet:
$optimization_attrs = wp_get_loading_optimization_attributes(
'img',
array(
'width' => $width,
'height' => $height,
'loading' => $loading_val,
'fetchpriority' => $fetchpriority_val,
'decoding' => $decoding_val,
),
$context
);
Change History (15)
#1
@
21 months ago
- Milestone changed from Awaiting Review to Future Release
- Version changed from 6.5.4 to 6.4
#2
@
21 months 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.
21 months ago
#3
- Keywords has-patch added
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
20 months ago
#7
@
20 months 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.
20 months ago
#8
- Keywords has-unit-tests added; needs-unit-tests removed
Trac ticket:
@mukesh27 commented on PR #6830:
18 months ago
#10
@deepakrohillas Left some suggestion other then it looks good to me.
#11
@
18 months ago
- Keywords changes-requested added
@deepakrohilla, I’ve left some feedback on the PR!
@adamsilverstein or @joemcgill, could one of you please assign yourself for the owner?
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
18 months ago
#13
@
18 months ago
- Keywords changes-requested removed
- Owner set to flixos90
- Status changed from new to reviewing
@flixos90 commented on PR #6830:
18 months ago
#15
Committed in https://core.trac.wordpress.org/changeset/58974
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 thesrcnor the actual image towp_get_loading_optimization_attributes()where the filter is called. There are other places where thesrcis passed, like inget_header_image_tag()orWP_Widget_Media_Image::render_media, but it probably makes sense to make this consistent.Thanks for the report!