Home › Forums › WoodMart support forum › Stop lazy loading spesfic images
Stop lazy loading spesfic images
- This topic has 6 replies, 2 voices, and was last updated 2 years, 1 month ago by Elise Noromit.
Viewing 7 posts - 1 through 7 (of 7 total)
-
AuthorPosts
-
November 6, 2022 at 5:10 pm #419022
allgoodkeysParticipantI want to exclude this images from lazy loading function
November 7, 2022 at 5:54 am #419092
Elise NoromitMemberHello,
Your purpose is not clear enough.
Could you kindly provide more details of what you want to change?
Best Regards
November 7, 2022 at 8:17 pm #419347
allgoodkeysParticipantI want to stop lazy loading for this images and logo
November 7, 2022 at 8:19 pm #419349
allgoodkeysParticipantAttached images
Attachments:
You must be logged in to view attached files.November 9, 2022 at 3:58 am #419671
Elise NoromitMemberHello,
I am afraid it is not possible. This option is global. Please provide your site admin access we will check how it works to suggest a solution.
Best Regards
November 10, 2022 at 8:20 pm #420224
allgoodkeysParticipantlogin details
November 12, 2022 at 3:00 am #420516
Elise NoromitMemberHello,
Please add this code to the functions.php of the child theme:
if ( ! function_exists( 'woodmart_filter_elementor_images' ) ) { /** * Filters HTML <img> tag and adds lazy loading attributes. Used for elementor images. * * @since 1.0.0 * * @param string $html Image html. * @param array $settings Control settings. * @param string $image_size_key Optional. Settings key for image size. * @param string $image_key Optional. Settings key for image.. * * @return string|string[]|null */ function woodmart_filter_elementor_images( $html, $settings, $image_size_key, $image_key ) { if ( preg_match( "/src=['\"]data:image/is", $html ) ) { return $html; } $exclude_images = array( 'Office-2021-is-here-all-good-keys-banner.png', 'operating-systems-all-good-keys-banner-1.png', 'Microsoft-products-all-good-keys-banner-1.png', 'Windows-servers-all-good-keys-banner-1.png', ); if ( ! empty( $settings['image']['url'] ) && $exclude_images ) { foreach ( $exclude_images as $image ) { if ( false !== strpos( $settings['image']['url'], $image ) ) { return $html; } } } $image = $settings[ $image_key ]; $image_sizes = get_intermediate_image_sizes(); $image_sizes[] = 'full'; $size = $settings[ $image_size_key . '_size' ]; if ( $image['id'] && in_array( $size, $image_sizes ) ) { // phpcs:ignore return $html; } if ( $image['id'] ) { $lazy_image = woodmart_get_attachment_placeholder( $image['id'], $size ); } else { $lazy_image = woodmart_lazy_get_default_preview(); } woodmart_enqueue_js_script( 'lazy-loading' ); return woodmart_lazy_replace_image( $html, $lazy_image ); } } if( ! function_exists( 'woodmart_lazy_attributes' ) ) { function woodmart_lazy_attributes($attr, $attachment, $size) { $exclude_images = array( 'Office-2021-is-here-all-good-keys-banner.png', 'operating-systems-all-good-keys-banner-1.png', 'Microsoft-products-all-good-keys-banner-1.png', 'Windows-servers-all-good-keys-banner-1.png', ); if ( ! empty( $attr['src'] ) && $exclude_images ) { foreach ( $exclude_images as $image ) { if ( false !== strpos( $attr['src'], $image ) ) { return $attr; } } } $attr['data-wood-src'] = $attr['src']; if( isset( $attr['srcset'] ) ) $attr['data-srcset'] = $attr['srcset']; if ( is_object( $attachment ) ) { $attr['src'] = woodmart_get_attachment_placeholder( $attachment->ID, $size ); } $attr['srcset'] = ''; $attr['class'] = $attr['class'] . ' ' . woodmart_lazy_css_class(); woodmart_enqueue_js_script( 'lazy-loading' ); return $attr; } }
You will find two functions with two variables
$exclude_images
and we have added image titles. If you change the titles of the images, you need to replace the titles.Best Regards
-
AuthorPosts
Viewing 7 posts - 1 through 7 (of 7 total)
- You must be logged in to create new topics. Login / Register