Making WordPress.org


Ignore:
Timestamp:
08/13/2024 03:36:23 AM (2 years ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@72a60f7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2024/functions.php

    r13944 r13965  
    2828 */
    2929add_action( 'after_setup_theme', __NAMESPACE__ . '\setup' );
     30add_filter( 'wp_get_attachment_image_attributes', __NAMESPACE__ . '\eager_load_first_card_row_images', 10, 3 );
    3031add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
    3132add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\maybe_enqueue_sensei_assets', 100 );
     
    139140
    140141/**
     142 * Eagerly load the images for the first row of cards, for performance (LCP metric).
     143 *
     144 * @param array   $attr       The image attributes.
     145 * @param WP_Post $attachment The attachment post object.
     146 * @param string  $size       The image size.
     147 * @return array The modified image attributes.
     148 */
     149function eager_load_first_card_row_images( $attr, $attachment, $size ) {
     150        static $image_count = 0;
     151
     152        if ( is_front_page() || is_archive() || is_search() || is_page( 'my-courses' ) ) {
     153                $image_count++;
     154
     155                if ( $image_count <= 3 ) {
     156                        $attr['loading'] = 'eager';
     157                        $attr['fetchpriority'] = 'high';
     158                }
     159        }
     160
     161        return $attr;
     162}
     163
     164/**
    141165 * Sensei doesn't enqueue learning mode styles for Lessons which are not part of a course.
    142166 * Enqueue the styles and add the required body class if needed.
     
    365389function set_default_featured_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
    366390        if ( ! $html ) {
    367                 return '<img src="https://s.w.org/images/learn-thumbnail-fallback.jpg?v=4" alt="' . esc_attr( get_the_title( $post_id ) ) . '" />';
     391                return '<img src="https://s.w.org/images/learn-thumbnail-fallback.jpg?v=5" alt="' . esc_attr( get_the_title( $post_id ) ) . '" />';
    368392        }
    369393
Note: See TracChangeset for help on using the changeset viewer.