[Resolved] LCP issue, featured image, srcset & scaled images

Home Forums Support [Resolved] LCP issue, featured image, srcset & scaled images

Home Forums Support LCP issue, featured image, srcset & scaled images

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #1374721
    Margaret

    Yes, I readded the code just now. Thanks!

    add_filter( 'wp_get_attachment_image_attributes', function( $attr ) {
        $attr['class'] .= ' skip-lazy';
    
        return $attr;
    } );
    #1375075
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this instead:

    add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment ) {
        if ( $attachment->ID === get_post_thumbnail_id() ) {
            $attr['class'] .= ' skip-lazy';
        }
    
        return $attr;
    }, 10, 2 );
    #1375281
    Margaret

    Thank you, that snippet worked perfectly! Last question on this topic – I just realized, I should probably add the “skip-lazy” class to the logo because that image is above the fold as well. How could I add the skip-lazy class to the logo? Could I edit the existing PHP snippet or add another?

    #1375637
    David
    Staff
    Customer Support

    Try adding this PHP Snippet:

    // Add skip-lazy class to mobile logo
    add_filter( 'generate_mobile_header_logo_output', function( $output ) {
      if ( ! function_exists( 'generate_menu_plus_get_defaults' ) ) {
          return $output;
      }
    
      $settings = wp_parse_args(
          get_option( 'generate_menu_plus_settings', array() ),
          generate_menu_plus_get_defaults()
      );
    
      return sprintf(
          '<div class="site-logo mobile-header-logo">
              <a href="%1$s" title="%2$s" rel="home">
                  <img src="%3$s" class="skip-lazy" alt="%4$s" />
              </a>
          </div>',
          esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
          esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
          esc_url( apply_filters( 'generate_mobile_header_logo', $settings['mobile_header_logo'] ) ),
          esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) )
      );
    } );
    
    // Add skip-lazy class to navigation logo
    add_filter( 'generate_logo_attributes', function( $attr ) {
      $attr['class'] .= ' skip-lazy';
    
      return $attr;
    } );
    #1378591
    Margaret

    Thank you!

    #1378884
    David
    Staff
    Customer Support

    You’re welcome

Viewing 6 posts - 16 through 21 (of 21 total)
  • You must be logged in to reply to this topic.