{"id":46645,"date":"2026-10-10T17:17:34","date_gmt":"2026-10-10T17:17:34","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46645"},"modified":"2026-10-10T17:17:34","modified_gmt":"2026-10-10T17:17:34","slug":"disable-lazy-load-wordpress","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/disable-lazy-load-wordpress\/","title":{"rendered":"Disable Lazy Load in WordPress Without a Plugin"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress adds <code>loading=\"lazy\"<\/code> 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet turns off the native attribute for images and iframes with one filter, wherever WordPress would add it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\nadd_filter( 'wp_lazy_loading_enabled', 'dpc_disable_lazy_loading', 10, 2 );\n\n\/**\n * Stop WordPress from adding loading=\"lazy\" to images and iframes.\n *\/\nfunction dpc_disable_lazy_loading( $enabled, $tag_name ) {\n\t$disabled_tags = array( 'img', 'iframe' );\n\n\tif ( in_array( $tag_name, $disabled_tags, true ) ) {\n\t\treturn false;\n\t}\n\n\treturn $enabled;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> ships this snippet in its One-Click Import library. To add it by hand:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In wp-admin go to <strong>Scripts Organizer \u2192 Code Blocks \u2192 Add New<\/strong> and give the block a title.<\/li>\n\n\n<li><strong>Script location<\/strong>: PHP.<\/li>\n\n\n<li><strong>Trigger location<\/strong>: Everywhere. Images are rendered on the front end, in feeds and in REST responses, so the filter should be registered on every request.<\/li>\n\n\n<li><strong>Action hook<\/strong>: leave it empty. The code only registers filters and actions, so it can run while plugins load.<\/li>\n\n\n<li>Paste the snippet into the PHP editor, enable the block and publish it.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin file in <code>wp-content\/mu-plugins\/<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before WordPress adds the attribute, it calls <code>wp_lazy_loading_enabled()<\/code> with the tag name (<code>img<\/code> or <code>iframe<\/code>) and a context such as <code>the_content<\/code> or <code>wp_get_attachment_image<\/code>. That function passes its answer through the <code>wp_lazy_loading_enabled<\/code> filter. Returning <code>false<\/code> for a tag means WordPress adds no <code>loading=\"lazy\"<\/code> to it, whether the markup comes from post content, featured images, widgets or block templates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 <code>decoding=\"async\"<\/code> and <code>fetchpriority=\"high\"<\/code> where it normally would; those are separate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Compared with the older <code>__return_false<\/code> version, the result for images and iframes is the same, but the tag list is now explicit and easy to change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'wp_lazy_loading_enabled', 'dpc_disable_lazy_loading_in_content', 10, 3 );\n\nfunction dpc_disable_lazy_loading_in_content( $enabled, $tag_name, $context ) {\n\tif ( 'the_content' === $context ) {\n\t\treturn false;\n\t}\n\n\treturn $enabled;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To keep lazy loading for embeds, which are heavy, remove <code>'iframe'<\/code> from <code>$disabled_tags<\/code>. If only the first images on a page are the problem, the <code>wp_omit_loading_attr_threshold<\/code> filter sets how many content images WordPress leaves eager (3 by default).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This removes only the attribute WordPress adds. <code>loading=\"lazy\"<\/code> hardcoded in a theme template, saved in a block&#8217;s HTML or added by an optimisation plugin stays; check that plugin&#8217;s settings.<\/li>\n\n\n<li>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.<\/li>\n\n\n<li>Page caches keep the old markup until they are cleared.<\/li>\n\n\n<li>For video embeds, a click-to-load approach like <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/youtube-shortcode-with-lazy-load-video-and-scripts-on-click\/\">YouTube Shortcode with lazy load video and scripts on click<\/a> saves more than the attribute does.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Disable WordPress native lazy loading for images and iframes with one filter, or limit it to post content when only some images are affected.<\/p>\n","protected":false},"author":1,"featured_media":46646,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Disable Lazy Load in WordPress Without a Plugin","description":"Disable WordPress native lazy loading for images and iframes with one filter, or limit it to post content when only some images are affected."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[132,3],"tags":[195,194,183,153],"dpc_library":[204],"class_list":["post-46645","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-performance","category-wordpress","tag-images","tag-lazy-loading","tag-media","tag-performance"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46645"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46645\/revisions"}],"predecessor-version":[{"id":46658,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46645\/revisions\/46658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46646"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46645"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46645"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}