fix: complete CHRNX responsive edge states
This commit is contained in:
15 files changed
+384
-35
No files matched your search
+5
-2
@@ -11,9 +11,10 @@
|
||||
* @param string $topic_slug Topic slug.
|
||||
* @param string $alt Alternative text. Empty is valid for decorative art.
|
||||
* @param string $class_name Optional image class.
|
||||
* @param string $loading Either lazy (default) or eager for above-fold art.
|
||||
* @return string Safe picture markup or an empty string.
|
||||
*/
|
||||
function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '', string $class_name = '' ): string {
|
||||
function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '', string $class_name = '', string $loading = 'lazy' ): string {
|
||||
$source = chrnx_get_topic_art_asset( $topic_slug );
|
||||
$dimensions = chrnx_get_topic_art_dimensions( $topic_slug );
|
||||
if ( '' === $source || 2 !== count( $dimensions ) ) {
|
||||
@@ -27,11 +28,13 @@ function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '',
|
||||
$classes = is_array( $split_classes ) ? array_filter( $split_classes ) : array();
|
||||
$class = implode( ' ', array_map( 'sanitize_html_class', $classes ) );
|
||||
$decorative = '' === $alt ? ' aria-hidden="true"' : '';
|
||||
$loading = 'eager' === $loading ? 'eager' : 'lazy';
|
||||
$priority = 'eager' === $loading ? ' fetchpriority="high"' : '';
|
||||
|
||||
$markup = '<picture class="chrnx-responsive-portrait"' . $decorative . '>';
|
||||
$markup .= '<source type="image/avif" srcset="' . esc_url( $base_uri . '-384.avif' ) . ' 384w, ' . esc_url( $base_uri . '-768.avif' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
|
||||
$markup .= '<source type="image/webp" srcset="' . esc_url( $base_uri . '-384.webp' ) . ' 384w, ' . esc_url( $base_uri . '-768.webp' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
|
||||
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( get_theme_file_uri( $source ) ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="lazy" decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
|
||||
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( get_theme_file_uri( $source ) ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="' . esc_attr( $loading ) . '"' . $priority . ' decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
|
||||
$markup .= '</picture>';
|
||||
|
||||
return $markup;
|
||||
|
||||
Reference in new issue
Block a user