| 开发者 |
jumedeenkhan
mozedia |
|---|---|
| 更新时间 | 2026年11月19日 15:36 |
| 捐献地址: | 去捐款 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv3 or later |
| 版权网址: | 版权信息 |
<picture> and <source> elements.data-bg attributes, retina images, multiple background layers, and image-set() variants.fetchpriority="high" to important images.loading="eager" and fetchpriority="high" attributes.skip-lazy class or data-skip-lazy attribute.<noscript> fallbacks, and lazy-loaded backgrounds use fallback CSS, so content stays visible without scripting.
Developer Friendly
Every filter uses the smart_lazyload_ prefix, so code can control processing, thresholds, placeholders, exclusions, and final markup with a few lines.
Setting the DONOTLAZYLOAD constant turns lazy loading off for a whole request, and WP-CLI commands generate or clear LQIP previews from the command line.
lazy-load-for-images folder./wp-content/plugins/ directory.Start with Smart to get the full set of loading controls, including background images and loading effects. Choose Hybrid to let the browser handle supported images and iframes and use JavaScript for the rest. Choose Native for simple, browser-managed loading without the frontend library. Background images load only in Smart and Hybrid modes.
Set the engine to Native under Settings → General. Native mode uses the browser's built-in loading="lazy" attribute, so the JavaScript library is not loaded.
To force native loading for every request regardless of the setting, use:
add_filter( 'smart_lazyload_use_native_lazyload', '__return_true' );
Use the page-type exclusions under Settings → General to skip the front page, blog index, archives, or search results. For a single post or page, use the Smart LazyLoad panel in the editor (Default / Enable / Disable).
Developers can also turn processing off for any request with the smart_lazyload_enabled or do_smart_lazyload filters.
For example, to skip only the search results page:
`
add_filter( 'smart_lazyload_enabled', 'disable_smart_lazyload_on_search' );
function disable_smart_lazyload_on_search( $enabled ) {
if ( is_search() ) {
return false;
}
return $enabled;
}
`
Under Settings → Performance, set the Loading Threshold to the distance in pixels before the viewport at which media starts loading.
The smart_lazyload_threshold filter can supply the value from code:
`
add_filter( 'smart_lazyload_threshold', 'set_smart_lazyload_threshold' );
function set_smart_lazyload_threshold() {
return 500;
}
`
Turn off YouTube Thumbnails under Settings → Content to keep video embeds as normal iframes, or disable Iframes to leave all embeds untouched.
The smart_lazyload_exclude_youtube_thumbnail filter takes an array of substrings: any embed whose markup contains one is kept as a normal iframe instead of getting a thumbnail. To keep one specific video as a player, add a substring to that array:
`
add_filter( 'smart_lazyload_exclude_youtube_thumbnail', 'smart_keep_video_as_iframe' );
function smart_keep_video_as_iframe( $patterns ) {
$patterns[] = 'youtube.com/watch?v=VIDEO_ID';
return $patterns;
}
`
The smart_lazyload_excluded_src filter skips any iframe by source URL substring. To leave a whole set of embeds untouched:
`
add_filter( 'smart_lazyload_excluded_src', 'smart_skip_embeds_by_url' );
function smart_skip_embeds_by_url( $patterns ) {
$patterns[] = 'youtube.com/embed/CHANNEL_ID';
return $patterns;
}
`
Enable Background Images under Settings → Content (and Background Variants if you use retina or image-set() markup). Backgrounds need Smart or Hybrid mode.
For manual markup, set a URL on an element and the plugin handles it:
<div class="smart-lazy-bg" data-bg="photo.jpg"></div>
The smart_lazyload_bg_images_regex filter changes which background-image expressions are matched.
To turn background-image lazy loading off entirely, use:
add_filter( 'smart_lazyload_background_images', '__return_false' );
Under Settings → Performance, enable Protect Important Images and choose the first image, first two images, or a custom count. These stay eager so the likely Largest Contentful Paint image loads immediately. Existing loading="eager" and fetchpriority="high" hints are respected too.
Under Settings → Placeholder, choose no placeholder, a low-quality image preview (LQIP), or a placeholder color, plus fade-in and spinner options.
The smart_lazyload_svg_placeholder filter replaces the default transparent SVG, and smart_lazyload_placeholder changes the placeholder used for iframes. To drop the placeholder so the image stays blank until it loads:
add_filter( 'smart_lazyload_dont_use_placeholder', '__return_true' );
Add the filter add_filter( 'smart_lazyload_noscript', '__return_false' );. The <noscript> tag is what keeps deferred images visible when JavaScript is disabled, so only remove it when you are sure you don't need that fallback.
Use the smart_lazyload_html filter to adjust the buffered HTML after all lazy-load passes have run:
There are several ways to exclude individual images:
loading="eager" or fetchpriority="high" to the image.skip-lazy, or no-lazyload CSS class in image.data-skip-lazy, data-no-lazy, or data-no-lazyload attribute.Yes. Smart LazyLoad processes the rendered frontend HTML without modifying your original media files. It works with most caching plugins and CDN configurations. After changing settings, clear your website cache and CDN cache so the updated settings take effect.
Yes. It processes the rendered frontend page, including content generated by page builders and theme templates. Page-builder editor previews are excluded automatically, and AMP pages are skipped by default.
Yes. Processed images, iframes, and videos include <noscript> fallbacks, and backgrounds use fallback CSS. Native mode relies on the browser's built-in behavior.
Yes. The Advanced tab has options to disable WordPress core lazy loading and Jetpack lazy loading so two systems never process the same media.
Not by default. Enable Advanced → Delete Data on Uninstall to remove settings, per-post overrides, and stored previews when the plugin is deleted. Deactivation never removes your settings.
Yes. Smart LazyLoad provides 18 developer filters covering processing, placeholders, thresholds, exclusions, markup, and media types:
do_smart_lazyload, smart_lazyload_enabled, smart_lazyload_thresholdsmart_lazyload_use_native_lazyload, smart_lazyload_background_imagessmart_lazyload_excluded_attachments, smart_lazyload_excluded_attributes, smart_lazyload_excluded_src, smart_lazyload_iframe_excluded_patternssmart_lazyload_placeholder, smart_lazyload_svg_placeholder, smart_lazyload_dont_use_placeholdersmart_lazyload_noscript, smart_lazyload_htmlsmart_lazyload_youtube_resolution, smart_lazyload_exclude_youtube_thumbnail, smart_lazyload_youtube_html, smart_lazyload_iframe_htmlsmart_lazyload_bg_images_regexsmart_lazyload_ prefix.