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

Allow prefixing autogenerated anchors in Heading blocks #38220

Open
priethor opened this issue Jan 25, 2022 · 1 comment
Open

Allow prefixing autogenerated anchors in Heading blocks #38220

priethor opened this issue Jan 25, 2022 · 1 comment
Labels
[Block] Heading Affects the Headings Block [Type] Enhancement A suggestion for improvement.

Comments

@priethor
Copy link
Contributor

What problem does this address?

The autogenerated HTML anchors introduced in Gutenberg 11.8 can create conflicts in some instances, like when duplicating Heading blocks or when users manually set an id, as it is not checked whether the same HTML ID exists on the page.

What is your proposed solution?

Adding a prefix to the anchors with the block name would avoid most conflicts with manually set IDs, except for particular situations. It would not prevent duplicate HTML IDs if two or more headings contain the same text, which semantically is not ideal anyway. Some options to consider:

  • Adding a block name prefix (header-mytitle)
  • Adding the block name and heading level (header-h3-mytitle): this can prevent conflicts between different heading levels with the same block, but the anchor would change if the user changes the heading level.

In any case, this prefix should be customizable with the help of a hook.

@priethor priethor added [Type] Enhancement A suggestion for improvement. [Block] Heading Affects the Headings Block labels Jan 25, 2022
@ram108
Copy link

ram108 commented Feb 2, 2022

Reference to related issue: #38171 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Heading Affects the Headings Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants