Skip to content

Instantly share code, notes, and snippets.

@brianleejackson
Created December 8, 2023 03:58
Show Gist options
  • Save brianleejackson/7a7a7a648e49fd665f6e1cb3a46c980d to your computer and use it in GitHub Desktop.
Save brianleejackson/7a7a7a648e49fd665f6e1cb3a46c980d to your computer and use it in GitHub Desktop.
Disable WordPress core fetch priority
function disable_fetchpriority_high( $loading_attrs ) {
unset( $loading_attrs['fetchpriority'] );
return $loading_attrs;
}
add_filter(
'wp_get_loading_optimization_attributes',
'disable_fetchpriority_high'
);
@Hasan101101
Copy link

Hasan101101 commented Jan 31, 2024

@brianleejackson thanks for your quick response.

yes, the code is working after disabling the fetchpriority feature from the Elementor.

Actually, I was forced to remove the fetchpriority feature because the fetchpriority was getting applied on the wrong image. I couldn't find any reason. Do you know how to fix this issue? or do you have any resources?

@brianleejackson
Copy link
Author

brianleejackson commented Jan 31, 2024

@Hasan101101 You might be able to use this snippet. You can control the size of the image that WordPress core fetch is getting applied to.

add_filter( 'wp_min_priority_img_pixels', function( $size ) { return 1000000; } );

FYI, we have WordPress core fetch disabled on all of our sites. The way it was implanted into WordPress core is not great. That's also why we added fetch into our plugin. https://perfmatters.io/docs/fetch-priority/ This way you can target anything you want. Although I usually recommend using a preload over fetch. But it depends on the site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment