fix a11y force empty alt for decorative images#475
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures that when callers explicitly pass an empty alt attribute to get_the_image(), the generated image markup preserves alt="" for accessibility by tracking this intent and post-processing the final HTML. Sequence diagram for get_the_image alt handlingsequenceDiagram
participant Caller
participant get_the_image
participant WordPress
Caller->>get_the_image: get_the_image(image_id, attributes, settings)
activate get_the_image
get_the_image->>get_the_image: Detect force_empty_alt (alt key exists and is empty)
get_the_image->>get_the_image: wp_parse_args(attributes, defaults)
get_the_image->>WordPress: wp_get_attachment_image(image_id, attributes)
WordPress-->>get_the_image: <img ... alt="from_attachment" ...>
get_the_image->>get_the_image: apply_filters(bea_theme_framework_the_image_markup)
alt force_empty_alt is true
get_the_image->>get_the_image: preg_replace alt="*" with alt=""
end
get_the_image-->>Caller: before + <img ... alt="" ...> + after
deactivate get_the_image
Flow diagram for forcing empty alt in get_the_imageflowchart TD
A[Start get_the_image] --> B[Check if attributes contains key alt]
B -->|No| C[force_empty_alt = false]
B -->|Yes and attributes alt is empty string| D[force_empty_alt = true]
B -->|Yes and attributes alt is not empty| E[force_empty_alt = false]
C --> F[Build attributes with wp_parse_args]
D --> F
E --> F
F --> G[Generate image markup via wp_get_attachment_image]
G --> H[Apply filter bea_theme_framework_the_image_markup]
H --> I{force_empty_alt?}
I -->|No| J[Return before + markup + after]
I -->|Yes| K[Use preg_replace to set alt="" in markup]
K --> J
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
preg_replacepattern'/\salt="[^"]*"/'assumes double quotes, a leading space, and an existingaltattribute; consider making the regex more robust (e.g., handle missing alt, varying whitespace, or single quotes) or using a DOM/attribute filter to modifyaltinstead of string replacement. - Currently the replacement runs on the whole
$image_markup; if there are multiple<img>tags in the markup, this could unintentionally alter all of them—consider scoping the change to the specific image or to the first occurrence only.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `preg_replace` pattern `'/\salt="[^"]*"/'` assumes double quotes, a leading space, and an existing `alt` attribute; consider making the regex more robust (e.g., handle missing alt, varying whitespace, or single quotes) or using a DOM/attribute filter to modify `alt` instead of string replacement.
- Currently the replacement runs on the whole `$image_markup`; if there are multiple `<img>` tags in the markup, this could unintentionally alter all of them—consider scoping the change to the specific image or to the first occurrence only.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
firestar300
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix des alt forcé vide qui étaient ignorés. Utile pour les images décoratives.
Forcer un alt vide lorsque
'alt' => ''est passé àthe_image()Quand on passait
'alt' => ''dans les attributs de l’image, la valeur n’était pas respectée : le filtre du frameworkbea_theme_framework_the_image_attributes(et/ouwp_get_attachment_image) continuait à utiliser l’alt de la pièce jointe renseigné en médiathèque.On détecte maintenant le cas où l’appelant demande explicitement un alt vide et, après génération du markup, on remplace l’attribut alt dans le HTML par
alt="", afin que les images décoratives (ex. dans les listes de cartes) aient bien un alt vide pour l’accessibilité.Summary by Sourcery
Bug Fixes: