eager_count = (int) apply_filters( 'ablocks/perf/lcp_eager_count', (int) Helper::get_settings( 'perf_lcp_eager_count', 1 ) ); add_filter( 'render_block', [ $self, 'process' ], 20, 2 ); } public function process( $content, $block ) { if ( empty( $block['blockName'] ) || false === strpos( $block['blockName'], 'ablocks' ) ) { return $content; } if ( false === strpos( $content, ']*\bloading=)[^>]*>/i', [ $this, 'rewrite_img' ], $content ); } private function rewrite_img( $matches ) { $tag = $matches[0]; $this->image_index++; if ( $this->image_index <= $this->eager_count ) { // Likely-LCP images: load eagerly with high priority. $attrs = ' loading="eager" fetchpriority="high"'; } else { $attrs = ' loading="lazy"'; } if ( false === stripos( $tag, 'decoding=' ) ) { $attrs .= ' decoding="async"'; } return preg_replace( '/^