Make WordPress Core

Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#57722 closed defect (bug) (invalid)

Loading property cannot be disabled in wp_get_attachment_image

Reported by: alexholsgrove's profile AlexHolsgrove Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.1.1
Component: Media Keywords:
Focuses: Cc:


In function wp_get_attachment_image() the docs suggest you can pass boolean “false” as part of the $attr for "loading" so that the attribute is omitted.

An example is also given in this article:

echo wp_get_attachment_image(
    array( 'loading' => false ),

However the property is still added (as loading="lazy"), caused by wp-includes/media.php function wp_filter_content_tags().

Change History (4)

#1 @costdev
15 months ago

  • Keywords reporter-feedback added

Reproduction Report

This report validates that the issue can be reproduced.

Steps to Reproduce or Test

  1. Navigate to Media > Add New and upload an image.
  2. Create a new file: wp-content/plugins/test_wp_get_attachment_image.php with the following contents:
     * Plugin Name: Test <code>wp_get_attachment_image()</code>
     * Description: Tests <code>wp_get_attachment_image()</code>.
     * Author:      WordPress Core Contributors
     * Author URI:
     * License:     GPLv2 or later
     * Version:     1.0.0
            function() {
                    $attachment = get_posts(
                                    'orderby'        => 'rand',
                                    'numberposts'    => 1,
                                    'post_type'      => 'attachment',
                                    'post_mime_type' => 'image',
                                    'post_status'    => 'inherit',
                    $image = wp_get_attachment_image(
                            array( 'loading' => false ),
                            '<div class="notice notice-info">%s</div>',
                            esc_html( $image )
  3. Navigate to Plugins > Installed plugins and activate "Test wp_get_attachment_image()".
  4. Check the output in the admin notice.

Expected Results

  • 🐞 The loading="lazy" attribute is still added.


  • Server: Apache (Linux)
  • WordPress: 6.2-beta2-55340-src and WordPress 6.1.1
  • Browser: Chrome
  • OS: Windows 10
  • Theme: Twenty Twenty-Two
  • Plugins:
    • Test wp_get_attachment_image() 1.0.0

Actual Results

  • ❌ Could not reproduce on WordPress 6.2-beta2-55340-src or WordPress 6.1.1.


  • @AlexHolsgrove Is there any information missing from your report, or my steps above, to reproduce this issue?
Last edited 15 months ago by costdev (previous) (diff)

#2 @AlexHolsgrove
15 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Thanks @costdev - your test shows the function working correctly. I also moved this to my front-end template and also worked correctly.

I can repeat my issue, however if I place the code inside a Gutenberg block template, using Advanced Custom Fields, so I believe the issue is with their plugin calling one of the filters.

Happy to close this as a non-issue.

#3 @SergeyBiryukov
15 months ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted

Thanks for the follow-up!

#4 @SergeyBiryukov
15 months ago

  • Component changed from General to Media
Note: See TracTickets for help on using tickets.