Skip to content

Fix Table of Contents block links on initial page save#70386

Open
Sukhendu2002 wants to merge 1 commit intoWordPress:trunkfrom
Sukhendu2002:fix/toc-initial-links
Open

Fix Table of Contents block links on initial page save#70386
Sukhendu2002 wants to merge 1 commit intoWordPress:trunkfrom
Sukhendu2002:fix/toc-initial-links

Conversation

@Sukhendu2002
Copy link
Contributor

@Sukhendu2002 Sukhendu2002 commented Jun 11, 2025

What?

Closes: #43595

Fixes Table of Contents block links that don't work on initial page save.

Testing Instructions

  1. Set WordPress permalink structure to "Post name" (Settings > Permalinks)
  2. Create a new Page
  3. Add several heading blocks (H2, H3) with content
  4. Add the Table of Contents block
  5. Publish the page
  6. View the published page
  7. Verify TOC links work correctly on initial publish (no "Page not found" errors)
  8. Also test in Preview mode to confirm links work there too

Screenshots or screencast

Before

before.mp4

After

after.mp4

@Sukhendu2002 Sukhendu2002 marked this pull request as ready for review June 11, 2025 10:40
@github-actions
Copy link

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @mahnunchik, @Greatdane.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: mahnunchik, Greatdane.

Co-authored-by: Sukhendu2002 <sukhendu2002@git.wordpress.org>
Co-authored-by: aatanasovdev <aatanasov@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: foosantos <foosantos@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines -68 to -76
let headingPageLink = null;

// If the core/editor store is available, we can add permalinks to the
// generated table of contents.
if ( typeof permalink === 'string' ) {
headingPageLink = isPaginated
? addQueryArgs( permalink, { page: headingPage } )
: permalink;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this logic will break the ToC block in paginated pages/posts. If I remember correctly, that was the reason it requires a permalink.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Table of contents (experimental) Affects the Table of contents Block labels Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Table of contents (experimental) Affects the Table of contents Block [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table of contents block – links don't work on initial page save

3 participants