[wp-trac] [WordPress Trac] #62686: Support for data-* attributes in Gutenberg blocks
WordPress Trac
noreply at wordpress.org
Fri Dec 13 14:40:20 UTC 2024
#62686: Support for data-* attributes in Gutenberg blocks
-----------------------------+------------------------------
Reporter: tunyk | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version:
Severity: normal | Resolution:
Keywords: close | Focuses:
-----------------------------+------------------------------
Changes (by swissspidy):
* keywords: => close
* focuses: ui, administration, template, performance, coding-standards =>
Comment:
Hi there and welcome to WordPress Trac!
Note that Gutenberg-specific feature requests are best submitted at
https://github.com/WordPress/gutenberg, as that's where development for
that part of WordPress happens.
It's expected behavior for a Gutenberg block to return such an error if
there is unknown markup in the content that can't be accounted for. You
should not manually edit the HTML of blocks, because the HTML is not the
source of truth, it is only generated based on the block's properties
(block attributes). When saving a block, the editor doesn't know where
your custom markup is coming from, be it a data-* attribute or something
else. You would need to first add support for that.
When you build a plugin for adding such custom HTML attributes through the
editor, you'll want to use JS filters such as
[https://developer.wordpress.org/block-editor/reference-guides/filters
/block-filters/#blocks-getsavecontent-extraprops
`blocks.getSaveContent.extraProps`] to ensure this HTML attribute is
present in the generated HTML. You'll also want a new ''block'' attribute
if you want to be able to control the behavior through the UI (i.e. a
toggle for turning that on or off).
Alternatively, for programmatically adding custom attributes you could use
the server-side HTML API.
There is prior discussion about this at
https://github.com/WordPress/gutenberg/issues/16164, which seems to
contain almost like a tutorial. So I'd suggest continuing the discussion
there if you have any questions.
Again, that GitHub repository is the way to go for Gutenberg-specific
requests.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62686#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list