Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Meta Block to control page description #253

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Aug 25, 2022

I saw this comment in WordPress/wporg-main-2022#79

maybe the solution to this is to have a special block in the post/pattern that specifies the meta description.

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:

<!-- wp:wporg/meta-block {"description":"Download WordPress today, and get started on creating your website with one of the most powerful, popular, and customizable platforms in the world."} /-->

When viewed in the editor, it's just a placeholder:
Screen Shot 2022-08-25 at 4 46 20 PM

The description itself is in the sidebar:
Screen Shot 2022-08-25 at 4 46 41 PM

And it does correctly inject the description into the page:
Screen Shot 2022-08-25 at 4 47 51 PM

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

  • Build the branch
  • Insert a Meta Block into your page, or copy the block code above into a template
  • View the page source
  • The <meta name="description" and other description meta should use the string from your block

Try 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.

@ryelle ryelle self-assigned this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant