Add new Meta Block to control page description #253
Closed
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.
I saw this comment in WordPress/wporg-main-2022#79
and decided to give it a shot. I've got a dynamic block with a description attribute. When rendering on the frontend, it returns an empty string, but sets up a filter on
jetpack_open_graph_tags
to set the description to the one from its attributes. This works for setting the page descriptions, but unfortunately doesn't work as well for the embed excerpt, since the block isn't rendered there.I tried getting around that by updating the excerpt directly when this attribute is changed, but that will only happen when someone edits the content in the editor, not via the pattern code.
Example of the block in a pattern:
When viewed in the editor, it's just a placeholder:
The description itself is in the sidebar:
And it does correctly inject the description into the page:
We could move the text field into the main content of the editor, but I wanted to keep text inputs out of the WYSIWYG section.
This could be expanded if we need to set other meta information per page, like title, etc.
To test
<meta name="description"
and other description meta should use the string from your blockTry visiting the embed page,
your-url/embed/
— if you set the description on the block in the editor, your description should appear in the embed.