Making WordPress.org


Ignore:
Timestamp:
09/03/2024 04:51:13 AM (17 months ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@d87d9b3

File:
1 edited

Legend:

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

    r14005 r14016  
    5555add_filter( 'single_template_hierarchy', __NAMESPACE__ . '\modify_single_template' );
    5656add_filter( 'taxonomy_template_hierarchy', __NAMESPACE__ . '\modify_taxonomy_template_hierarchy' );
     57add_filter( 'wp_calculate_image_sizes', __NAMESPACE__ . '\modify_grid_image_sizes', 10, 5 );
    5758add_filter( 'wp_get_attachment_image_attributes', __NAMESPACE__ . '\eager_load_first_card_rows_images', 10, 3 );
    5859add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );
     
    167168
    168169    return $attr;
     170}
     171
     172/**
     173 * Modify the image sizes attribute to improve performance by loading the size that is closest to the grid column width.
     174 */
     175function modify_grid_image_sizes( $sizes, $size, $image_src, $image_meta, $attachment_id ) {
     176    if ( is_front_page() || is_archive() || is_search() || is_page( 'my-courses' ) ) {
     177        return '(max-width: 768px) 100vw, (max-width: 1270px) 50vw, 33vw';
     178    }
     179
     180    return $sizes;
    169181}
    170182
Note: See TracChangeset for help on using the changeset viewer.