Skip to content

newspack_post_thumbnail() causing warning message due to presence of lazy loading and fetch priority attributes #2392

@edmundcwm

Description

@edmundcwm

Describe the bug
In the newspack_post_thumbnail() template tag, there's a chance that the default attributes being set can contain both loading="lazy" and fetchpriority="high". This will trigger a warning when the wp_get_loading_optimization_attributes() Core function is called since images that are lazy loaded should not be marked as high priority at the same time.

To Reproduce
Steps to reproduce the behavior:

  1. Create a few posts with featured image
  2. Visit the post archive page on the frontend
  3. With WP_Debug enabled, the following warning message should be displayed - Notice: Function wp_get_loading_optimization_attributes was called <strong>incorrectly</strong>. An image should not be lazy-loaded and marked as high priority at the same time. Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.3.0.)...

Screenshots
Markup of a post featured image in the archive page that contains both the loading="lazy" and fetchpriority="high" attributes
Image

Warning message from Query monitor (path to wp-includes/functions.php has been redacted)
Image

Expected behavior
If an image has the loading="lazy" attribute then it should not have fetchpriority="high" as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions