Skip to content

Heading Block: autogenerate anchors #29561

@aristath

Description

@aristath

What problem does this address?

Heading blocks are significant structural elements in posts, and being able to link to them is a must-have. There is no downside to having an id in headings, and they are immensely useful:

  • Search engines can link to a section of the post directly
  • Users can share their content more efficiently
  • The Table of Contents block will be able to link to all headings in the content

What is your proposed solution?

This is a proposal to auto-generate anchors for heading blocks.
When the user adds a heading we can generate the anchor from the heading text, so "About Me" gets an anchor about-me.
The user will still be able to customize their anchor from the block's "Advanced" section if they wish.

What happens if the user edits the heading text?

If the heading was About Me with an anchor about-me and they change their heading to About Us, then we can detect that about-me matches the auto-generated anchor for the About Me text, and change the anchor to about-us. If on the other hand the initial anchor doesn't match (for example section-1) then assume it was customized by the user and leave it alone.

What about non-latin languages?

Though not strictly necessary, we could transliterate headings when generating the anchors, just so we get prettier URLs.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions