开发者 |
aryadhiratara
thinkwebdev |
---|---|
更新时间 | 2023年5月21日 23:24 |
PHP版本: | 7.4 及以上 |
WordPress版本: | 6.2 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
lazysizes.js
. No jquery dependency.no-lazy
and skip-lazy
class as default exclude class for lazyloading images.loading eager
to also target no-lazy
and skip-lazy
class.no-lazy
class) from lazyloading if Preload Featured Images
feature is enabled (useful to avoid Largest Contentful Paint image was lazily loaded
warning in Google Pagespeed Insights ).webp
extension to CDN HTML rewrite regex.background-image
property. Tested and works well on CSS background image from GenerateBlocks
, Elementor
, and Oxygen Builder
.loading=eager
to the lazy load excluded list.no-lazy
or skip-lazy
class.Plugins > Add New
Optimize More Images
optimize-more-images
folder to your /wp-content/plugins/
directoryMore configurable.
Lazy loading css background images requires some effort from your end. Add an extra lazyload
class to each container which has css background image in your favorite page editor. Or, simply put (one of) the container class in the include list field, the plugin will automatically add an extra lazyload
class to the container.
This actually a good practice to add extra performance boost to your WordPress site. On WordPress single post and WooCommerce single product pages, featured images usually appear on above the fold section, so it's better to preload them to avoid render blocking issues, just like any assets which required in above the fold section. We can adapt this single post and single product behaviour in pages too. Set your hero / above the fold images as featured images to programatically, and automatically, preload them on all pages.
It calls images set as featured image in the native WordPress post/pages, using get_post_thumbnail_id()
and wp_get_attachment_image_src()
. Make sure you already adds them.
If you are using Elementor or other Page's builders, simply edit the pages with the native WordPress editor to set the featured image.
By default, this plugin will be grab the url and preload the full
image size and woocommerce_single
for WooCommerce single product pages. You can change that using filter if your theme is uses different image size
. See example below.
Here are some examples: add_filter( 'preload_featured_images_image_size', function( $image_size, $post ) { if ( is_singular( 'post' ) ) { return 'large'; } elseif ( is_singular( 'product' ) ) { return 'full'; } else { return $image_size; } }, 10, 2 );
Example if you want to include svg to your image CDN: add_filter( 'opm_cdn_file_types', function($opm_cdn_file_types) { return $opm_cdn_file_types . '|svg'; } ); Example if you want to completely change the default file types: add_filter( 'opm_cdn_file_types', function($opm_cdn_file_types) { return 'png|webp|svg'; } );
This depends on you theme or overal site's setup and how you upload your images. If it fails to grab the width and height of your images, you can specify the default image width and height fallback values that best suit your website situation in the provided fields.
no-lazy
and skip-lazy
class to lazy load background imagesjpg|jpeg|png|webp
as the default file types for CDN HTML rewrite regexopm_cdn_file_types
filter to change the file types of CDN HTML rewrite regex (see FAQ)no-lazy
and skip-lazy
class as default exclude class for lazyloading imagesloading eager
to also target no-lazy
and skip-lazy
classno-lazy
class) from lazyloading if Preload Featured Images
feature is enabled (useful to avoid Largest Contentful Paint image was lazily loaded
warning in Google Pagespeed Insights)preload_featured_images_image_size
filter to change the image size
of featured image
in the plugin's FAQ.webp
and svg
to CDN HTML rewrite regexdns-prefetch
for CDN url