Improve hero imagery accessibility and CTA fallbacks#35
Conversation
Summary of ChangesHello @GalToast, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the theme's accessibility and reliability. It improves how hero images are rendered to ensure proper alt text, responsive image sources, and lazy-loading are utilized. Additionally, it refines the presentation of static call-to-action elements, making them accessible to assistive technologies while visually distinguishing them from active links. The update also includes a fix for the home page seeding process, preventing issues when a "Home" page is in the trash, and aligns the documented WordPress compatibility with the theme's actual requirements. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable accessibility improvements and bug fixes. The changes to render hero images using attachment IDs for better accessibility, make static CTAs visible to assistive technologies, and handle trashed pages during home page seeding are all well-implemented. The documentation updates are also thorough and align with the code changes. I've found one area in the hero block's render file where the code could be refactored to reduce duplication, for which I've provided a suggestion.
| $hero_image_markup = ''; | ||
|
|
||
| if ( 0 !== $hero_image_id ) { | ||
| $image_attributes = array( | ||
| 'class' => 'hero__decorative-image', | ||
| 'loading' => 'lazy', | ||
| 'alt' => $hero_image_alt, | ||
| ); | ||
|
|
||
| if ( '' === $hero_image_alt ) { | ||
| $image_attributes['role'] = 'presentation'; | ||
| } | ||
|
|
||
| $hero_image_markup = wp_get_attachment_image( $hero_image_id, 'full', false, $image_attributes ); | ||
|
|
||
| if ( ! $hero_image_markup && '' !== $hero_image_url ) { | ||
| $fallback_attributes = $image_attributes; | ||
| $fallback_attributes['src'] = $hero_image_url; | ||
|
|
||
| $hero_image_markup = '<img'; | ||
|
|
||
| foreach ( $fallback_attributes as $attr_name => $attr_value ) { | ||
| $escaped_value = 'src' === $attr_name ? esc_url( $attr_value ) : esc_attr( $attr_value ); | ||
| $hero_image_markup .= sprintf( ' %s="%s"', esc_attr( $attr_name ), $escaped_value ); | ||
| } | ||
|
|
||
| $hero_image_markup .= ' />'; | ||
| } | ||
| } elseif ( '' !== $hero_image_url ) { | ||
| $attr_pairs = array( | ||
| 'src' => $hero_image_url, | ||
| 'class' => 'hero__decorative-image', | ||
| 'loading' => 'lazy', | ||
| 'alt' => $hero_image_alt, | ||
| ); | ||
|
|
||
| if ( '' === $hero_image_alt ) { | ||
| $attr_pairs['role'] = 'presentation'; | ||
| } | ||
|
|
||
| $hero_image_markup = '<img'; | ||
|
|
||
| foreach ( $attr_pairs as $attr_name => $attr_value ) { | ||
| $escaped_value = 'src' === $attr_name ? esc_url( $attr_value ) : esc_attr( $attr_value ); | ||
| $hero_image_markup .= sprintf( ' %s="%s"', esc_attr( $attr_name ), $escaped_value ); | ||
| } | ||
|
|
||
| $hero_image_markup .= ' />'; | ||
| } |
There was a problem hiding this comment.
The logic for manually building the <img> tag is duplicated in two places: once as a fallback for wp_get_attachment_image(), and again for when only a URL is provided. This can be refactored to a single block to improve maintainability and reduce code duplication.
$hero_image_markup = '';
$manual_img_attrs = null;
if ( 0 !== $hero_image_id ) {
$image_attributes = array(
'class' => 'hero__decorative-image',
'loading' => 'lazy',
'alt' => $hero_image_alt,
);
if ( '' === $hero_image_alt ) {
$image_attributes['role'] = 'presentation';
}
$hero_image_markup = wp_get_attachment_image( $hero_image_id, 'full', false, $image_attributes );
if ( ! $hero_image_markup && '' !== $hero_image_url ) {
$manual_img_attrs = $image_attributes;
$manual_img_attrs['src'] = $hero_image_url;
}
} elseif ( '' !== $hero_image_url ) {
$manual_img_attrs = array(
'src' => $hero_image_url,
'class' => 'hero__decorative-image',
'loading' => 'lazy',
'alt' => $hero_image_alt,
);
if ( '' === $hero_image_alt ) {
$manual_img_attrs['role'] = 'presentation';
}
}
if ( is_array( $manual_img_attrs ) ) {
$hero_image_markup = '<img';
foreach ( $manual_img_attrs as $attr_name => $attr_value ) {
$escaped_value = 'src' === $attr_name ? esc_url( $attr_value ) : esc_attr( $attr_value );
$hero_image_markup .= sprintf( ' %s="%s"', esc_attr( $attr_name ), $escaped_value );
}
$hero_image_markup .= ' />';
}|
jules could you handle the commit conflicts prioritizing most recent changes? This branch is old, from yesterday. |
Summary
.is-staticstates as neutral copy instead of faux linksTesting
https://chatgpt.com/codex/tasks/task_e_68ddfef9251083248e681d493cf6675a