-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Dynamically add CSS classe to Paragraph block #71207
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
Conversation
Size Change: -8 B (0%) Total Size: 1.91 MB
ℹ️ View Unchanged
|
3e56a26
to
f85fb8c
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
array( | ||
'render_callback' => 'block_core_paragraph_render', | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by setting this as a render_callback
we’re taking exclusive control over block rendering when all we’re doing is adding a class.
it may be more cooperative to implement the render_block_core/paragraph
filter. that render_block
interface will ruin us all 😄.
you can do the same thing using the filter but you won’t take an exclusive lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! Sorry, there is still some disagreement on whether paragraph blocks need CSS classes or not. I would like to move this PR to draft until we reach a consensus 😅
Let's freeze this PR until the discussion in #47282 decides on a direction. |
Alternatives to #47282
What?
This PR adds a block CSS class to the Paragraph block dynamically only.
Why?
We've been experimenting with adding a block CSS class to the Paragraph block, as we do to many other blocks. #47282 adds a CSS class to the saved block HTML itself, making it an irreversible change.
How?
Dynamically add a CSS class to the Paragraph block and change the global style selector from
p
to.wp-block-paragraph
only if theIS_GUTENBERG_PLUGIN
constant is defined and the value is true. This allows users to test the new behavior on sites that use the latest Gutenberg plugin. However, theclassName
support for the Paragraph block remains disabled, so the HTML saved to the database remains unchanged.If this change is favorable, we can gradually expand the scope of CSS classes as follows:
IS_GUTENBERG_PLUGIN
constant checkclassName: false
from theblock.json
so that the CSS classes are applied to the saved HTML as well.Testing Instructions
p
elements don't havewp-block-paragraph
CSS class.p
elements havewp-block-paragraph
CSS class.