Home Forums WoodMart support forum Stop lazy loading spesfic images

Stop lazy loading spesfic images

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #419022

    allgoodkeys
    Participant

    I want to exclude this images from lazy loading function

    #419092

    Hello,

    Your purpose is not clear enough.

    Could you kindly provide more details of what you want to change?

    Best Regards

    #419347

    allgoodkeys
    Participant

    I want to stop lazy loading for this images and logo

    #419349

    allgoodkeys
    Participant

    Attached images

    Attachments:
    You must be logged in to view attached files.
    #419671

    Hello,

    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

    #420224

    allgoodkeys
    Participant

    login details

    #420516

    Hello,

    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_imagesand we have added image titles. If you change the titles of the images, you need to replace the titles.

    Best Regards

Viewing 7 posts - 1 through 7 (of 7 total)