get_exclusions(); // Add loading="lazy" to img tags that don't already have it. $content = preg_replace_callback( '/]*)>/i', function ( $matches ) use ( $exclusions ) { $attributes = $matches[1]; // Skip if already has loading attribute. if ( preg_match( '/\bloading\s*=/i', $attributes ) ) { return $matches[0]; } // Skip excluded classes. if ( $this->has_excluded_class( $attributes, $exclusions ) ) { return $matches[0]; } return ''; }, $content ); // Add loading="lazy" to iframe tags that don't already have it. $content = preg_replace_callback( '/]*)>/i', function ( $matches ) use ( $exclusions ) { $attributes = $matches[1]; if ( preg_match( '/\bloading\s*=/i', $attributes ) ) { return $matches[0]; } if ( $this->has_excluded_class( $attributes, $exclusions ) ) { return $matches[0]; } return '