Viewing 1 replies (of 1 total)
  • Thread Starter juslintek

    (@juslintek)

    If someone has same issue and want temporary fix without hardcoding then, put this code in your theme functions.php

    
    remove_filter( 'get_avatar'         , 'rocket_lazyload_images', PHP_INT_MAX );
    remove_filter( 'the_content'        , 'rocket_lazyload_images', PHP_INT_MAX );
    remove_filter( 'widget_text'        , 'rocket_lazyload_images', PHP_INT_MAX );
    remove_filter( 'get_image_tag'      , 'rocket_lazyload_images', PHP_INT_MAX );
    remove_filter( 'post_thumbnail_html', 'rocket_lazyload_images', PHP_INT_MAX );
    
    function rocket_lazyload_images_override( $html ) {
    	// Don't LazyLoad if the thumbnail is in admin, a feed, REST API or a post preview.
    	if ( ! rocket_lazyload_get_option( 'images' ) || is_admin() || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || empty( $html ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) || wp_script_is( 'twentytwenty-twentytwenty', 'enqueued' ) ) {
    		return $html;
    	}
    
    	// You can stop the LalyLoad process with a hook.
    	if ( ! apply_filters( 'do_rocket_lazyload', true ) ) {
    		return $html;
    	}
    
    	return preg_replace_callback( '#<img([^>]*) src=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))([^>]*)>#', 'rocket_lazyload_replace_callback_fix', $html );
    }
    add_filter( 'get_avatar'         , 'rocket_lazyload_images_override', PHP_INT_MAX );
    add_filter( 'the_content'        , 'rocket_lazyload_images_override', PHP_INT_MAX );
    add_filter( 'widget_text'        , 'rocket_lazyload_images_override', PHP_INT_MAX );
    add_filter( 'get_image_tag'      , 'rocket_lazyload_images_override', PHP_INT_MAX );
    add_filter( 'post_thumbnail_html', 'rocket_lazyload_images_override', PHP_INT_MAX );
    
    /**
     * Used to check if we have to LazyLoad this or not
     *
     * @since 1.1 Don't apply LazyLoad on images from WP Retina x2
     * @since 1.0.1
     *
     * @param string $matches a string matching the pattern to find images in HTML code.
     * @return string Updated string with lazyload data
     */
    function rocket_lazyload_replace_callback_fix( $matches ) {
    	if ( function_exists( 'wr2x_picture_rewrite' ) ) {
    		if ( wr2x_get_retina( trailingslashit( ABSPATH ) . wr2x_get_pathinfo_from_image_src( trim( $matches[2], '"' ) ) ) ) {
    			return $matches[0];
    		}
    	}
    	$excluded_attributes = apply_filters( 'rocket_lazyload_excluded_attributes', array(
    		'data-no-lazy=',
    		'data-lazy-original=',
    		'data-lazy-src=',
    		'data-src=',
    		'data-lazysrc=',
    		'data-lazyload=',
    		'data-bgposition=',
    		'data-envira-src=',
    		'fullurl=',
    		'lazy-slider-img=',
    		'data-srcset=',
    		'class="ls-l',
    		'class="ls-bg',
    	) );
    
    	$excluded_src = apply_filters( 'rocket_lazyload_excluded_src', array(
    		'/wpcf7_captcha/',
    		'timthumb.php?src',
    	) );
    
    	if ( rocket_is_excluded_lazyload( $matches[1] . $matches[3], $excluded_attributes ) ||  rocket_is_excluded_lazyload( $matches[2], $excluded_src ) ) {
    		return $matches[0];
    	}
    
    	/**
    	 * Filter the LazyLoad placeholder on src attribute
    	 *
    	 * @since 1.1
    	 *
    	 * @param string $placeholder Placeholder that will be printed.
    	 */
    	$placeholder = apply_filters( 'rocket_lazyload_placeholder', "data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" );
    
    	$img = sprintf( '<img%1$s src=%4$s data-lazy-src=%2$s%3$s>', $matches[1], $matches[2], $matches[3], $placeholder );
    
    	$img_noscript = sprintf( '<noscript><img%1$s src=%2$s%3$s></noscript>', $matches[1], $matches[2], $matches[3] );
    
    	/**
    	 * Filter the LazyLoad HTML output
    	 *
    	 * @since 1.0.2
    	 *
    	 * @param array $img Output that will be printed
    	 */
    	$img = apply_filters( 'rocket_lazyload_html', $img, true );
    
    	return $img . $img_noscript;
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘Bug with quotation in sprintf’ is closed to new replies.