Fix inline image alt text not persisting in structured data blocks#23018
Open
param-chandarana wants to merge 1 commit intoYoast:trunkfrom
Open
Fix inline image alt text not persisting in structured data blocks#23018param-chandarana wants to merge 1 commit intoYoast:trunkfrom
param-chandarana wants to merge 1 commit intoYoast:trunkfrom
Conversation
Fixes a bug where alt text changes made via the inline image editor in How-to and FAQ blocks were not being reflected on the frontend. The optimize_images() method was replacing images with wp_get_attachment_image() which only used alt text from the media library database, ignoring inline edits saved in the block content. This fix extracts the alt text from the original image HTML before replacement and passes it to wp_get_attachment_image() to ensure it is preserved in the rendered output. Fixes Yoast#22905
d466316 to
347ca67
Compare
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.
Context
Image alt text edited inline in the Gutenberg editor for How-to and FAQ blocks was being lost when the blocks were rendered on the frontend. This is an accessibility and SEO issue, as alt text is crucial for both screen readers and search engine optimization.
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
The issue was in the
optimize_images()method inStructured_Data_Blocksclass. When rendering blocks on the frontend, this method replaces images with optimized versions usingwp_get_attachment_image(), which only used the attachment ID to pull alt text from the media library database, ignoring any inline edits saved in the block content.The fix:
wp_get_attachment_image()will encode them again)wp_get_attachment_image()via the$image_attrsparameterTest instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
altattribute should show "Custom Alt Text Test"Repeat the same steps for FAQ blocks:
Relevant test scenarios
Test instructions for QA when the code is in the RC
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
optimize_images()method has been modified, so verify that images are still properly optimized on the frontendOther environments
[shopify-seo], added test instructions for Shopify and attached theShopifylabel to this PR.[yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached theGoogle Docs Add-onlabel to this PR.Documentation
Quality assurance
grunt build:imagesand commited the results, if my PR introduces new images or SVGs. (No new images introduced)Innovation
innovationlabel.Fixes #22905