is_primary_sidebar_active() ) { $sizes = '(min-width: 960px) 60vw, 100vw'; } return $sizes; } /** * Filters the `sizes` value in the header image markup. * * @param string $html The HTML image tag markup being filtered. * @param object $header The custom header object returned by 'get_custom_header()'. * @param array $attr Array of the attributes for the image tag. * @return string The filtered header image HTML. */ public function filter_header_image_tag( string $html, $header, array $attr ) : string { if ( isset( $attr['sizes'] ) ) { $html = str_replace( $attr['sizes'], '100vw', $html ); } return $html; } /** * Adds custom image sizes attribute to enhance responsive image functionality for post thumbnails. * * @param array $attr Attributes for the image markup. * @param WP_Post $attachment Attachment post object. * @param string|array $size Registered image size or flat array of height and width dimensions. * @return array The filtered attributes for the image markup. */ public function filter_post_thumbnail_sizes_attr( array $attr, WP_Post $attachment, $size ) : array { // Exclude site logo. The sizes attribute may be specified only if the srcset attribute is also present. if ( $attr['class'] === 'custom-logo' ) { return $attr; } // Required for pages using grid-template.php. if ( $attr['class'] === 'skip-lazy' && isset( $attr['loading'] ) ) { unset( $attr['loading'] ); } $attr['sizes'] = '100vw'; if ( is_home() ) { $attr['sizes'] = '(min-width: 672px) 415px, (min-width: 1056px) 351px , (min-width: 1441px) 33vw, 100vw'; } elseif ( is_category() ) { $attr['sizes'] = '(min-width: 672px) 42vw, (min-width: 960px) 60vw, (min-width: 1064px) 30vw, 100vw'; } elseif ( ampy()->is_primary_sidebar_active() ) { $attr['sizes'] = '(min-width: 960px) 60vw, 100vw'; } return $attr; } }