Skip to content

Allow prefixing autogenerated anchors in Heading blocksΒ #38220

@priethor

Description

@priethor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions