From cfb2a66a817ff757ea71be770bee52a009ccd274 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:01:30 +1200 Subject: [PATCH] Perf: Increase number of eagerly loaded card images LCP image can end up being in the second row. See https://github.com/WordPress/Learn/issues/2679 --- wp-content/themes/pub/wporg-learn-2024/functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wp-content/themes/pub/wporg-learn-2024/functions.php b/wp-content/themes/pub/wporg-learn-2024/functions.php index 758c6782f..c2788dfe9 100644 --- a/wp-content/themes/pub/wporg-learn-2024/functions.php +++ b/wp-content/themes/pub/wporg-learn-2024/functions.php @@ -27,7 +27,7 @@ * Actions and filters. */ add_action( 'after_setup_theme', __NAMESPACE__ . '\setup' ); -add_filter( 'wp_get_attachment_image_attributes', __NAMESPACE__ . '\eager_load_first_card_row_images', 10, 3 ); +add_filter( 'wp_get_attachment_image_attributes', __NAMESPACE__ . '\eager_load_first_card_rows_images', 10, 3 ); add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' ); add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\maybe_enqueue_sensei_assets', 100 ); @@ -139,20 +139,20 @@ function enqueue_assets() { } /** - * Eagerly load the images for the first row of cards, for performance (LCP metric). + * Eagerly load the images for the first 2 rows of cards, for performance (LCP metric). * * @param array $attr The image attributes. * @param WP_Post $attachment The attachment post object. * @param string $size The image size. * @return array The modified image attributes. */ -function eager_load_first_card_row_images( $attr, $attachment, $size ) { +function eager_load_first_card_rows_images( $attr, $attachment, $size ) { static $image_count = 0; if ( is_front_page() || is_archive() || is_search() || is_page( 'my-courses' ) ) { $image_count++; - if ( $image_count <= 3 ) { + if ( $image_count <= 6 ) { $attr['loading'] = 'eager'; $attr['fetchpriority'] = 'high'; }