WordPress adds loading="lazy" to images and iframes by default. There are good reasons to disable lazy load in WordPress: a slider or gallery script that wants to control loading itself, a hero image from a page builder that shows up late, or a print stylesheet or screenshot tool that needs every image ready.
This snippet turns off the native attribute for images and iframes with one filter, wherever WordPress would add it.
The snippet
<?php
add_filter( 'wp_lazy_loading_enabled', 'dpc_disable_lazy_loading', 10, 2 );
/**
* Stop WordPress from adding loading="lazy" to images and iframes.
*/
function dpc_disable_lazy_loading( $enabled, $tag_name ) {
$disabled_tags = array( 'img', 'iframe' );
if ( in_array( $tag_name, $disabled_tags, true ) ) {
return false;
}
return $enabled;
}
Add it with Scripts Organizer
Scripts Organizer ships this snippet in its One-Click Import library. To add it by hand:
- In wp-admin go to Scripts Organizer → Code Blocks → Add New and give the block a title.
- Script location: PHP.
- Trigger location: Everywhere. Images are rendered on the front end, in feeds and in REST responses, so the filter should be registered on every request.
- Action hook: leave it empty. The code only registers filters and actions, so it can run while plugins load.
- Paste the snippet into the PHP editor, enable the block and publish it.
The same code also works unchanged in a small plugin or an mu-plugin file in wp-content/mu-plugins/.
How it works
Before WordPress adds the attribute, it calls wp_lazy_loading_enabled() with the tag name (img or iframe) and a context such as the_content or wp_get_attachment_image. That function passes its answer through the wp_lazy_loading_enabled filter. Returning false for a tag means WordPress adds no loading="lazy" to it, whether the markup comes from post content, featured images, widgets or block templates.
Other tags pass through unchanged, so if a future WordPress version lazy-loads a new element, this snippet does not switch it off by accident. WordPress still adds decoding="async" and fetchpriority="high" where it normally would; those are separate.
Compared with the older __return_false version, the result for images and iframes is the same, but the tag list is now explicit and easy to change.
Customise it
Turning lazy loading off everywhere makes every image below the fold download on page load. Often the problem is in one place. This version turns it off only in post content and keeps it for featured images and other attachment images:
add_filter( 'wp_lazy_loading_enabled', 'dpc_disable_lazy_loading_in_content', 10, 3 );
function dpc_disable_lazy_loading_in_content( $enabled, $tag_name, $context ) {
if ( 'the_content' === $context ) {
return false;
}
return $enabled;
}
To keep lazy loading for embeds, which are heavy, remove 'iframe' from $disabled_tags. If only the first images on a page are the problem, the wp_omit_loading_attr_threshold filter sets how many content images WordPress leaves eager (3 by default).
Gotchas
- This removes only the attribute WordPress adds.
loading="lazy"hardcoded in a theme template, saved in a block’s HTML or added by an optimisation plugin stays; check that plugin’s settings. - Measure before and after, with Lighthouse or the Network panel in your browser, rather than turning lazy loading off by habit. On long pages it usually saves bandwidth.
- Page caches keep the old markup until they are cleared.
- For video embeds, a click-to-load approach like YouTube Shortcode with lazy load video and scripts on click saves more than the attribute does.
In the Scripts Organizer library Import it with one click from Scripts Organizer.