title: Disable lazy load in lagest contentful paint in WordPress
body: <p>I found <a href="https://stackoverflow.com/a/65326178/19838182">this 2 year old solution</a> that essentially counts the  and removes the loading attribute where the count =1 and implimented via snippets plugin for Wordpress.</p>
  <p>Unfortunately GTMetrix is still flagging &quot;don't lazy load LCP&quot; and when I inspect the image in my browsers I still see the attribute loading=&quot;lazy&quot; for the 1st (and every) image on every post.</p>
  <p>I suspected it was counting the site logo in the header as the 1st image but it too has loading=&quot;lazy&quot; so it seems that the code isn't working at all.</p>
  <ul>
  <li>Wordpress 6.0.1</li>
  <li>Theme: Hello Elementor Child</li>
  <li>Elementor + Elementor Pro</li>
  <li>JetEngine for custom post type</li>
  <li>Imagify for webP conversion &amp; optimization</li>
  </ul>
  <p>I'm not running any lazy-loading plugin and don't want to disable wordpress's global lazy load for all images, just the one above the fold in the LCP.</p>
  <p>Snippet I'm running:</p>
  <pre><code>/* Remove lazy load first image */
  function add_responsive_class($content)
  {
      if ( is_single() || is_page() || is_front_page() || is_home() ) 
      {
          $content = mb_convert_encoding($content, 'HTML-ENTITIES', &quot;UTF-8&quot;);
          $document = new DOMDocument();
          libxml_use_internal_errors(true);
          $document-&gt;loadHTML(utf8_decode($content));
          $imgs = $document-&gt;getElementsByTagName('img');
          $img = $imgs[0];
          if ($imgs[0] == 1) 
          { // Check first if it is the first image
              $img-&gt;removeAttribute( 'loading' );
              $html = $document-&gt;saveHTML();
              return $html;
          }
          else 
          {
              return $content;
          }
      }
      else 
      {
          return $content;
      }
  }
  add_filter ('the_content', 'add_responsive_class');
  </code></pre>
  <p>If anyone can help me understand why this doesn't work on my site or has a different solution I'd appreciate the help.</p>