You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Table of contents block – links don't work on initial page save #43595
If you add the Table of Contents block to a new page, when you publish the page, the links don't work properly and instead open a new page with a Page not found error. The URL is retaining an auto-draft in it. If you edit and Update the page, the links will then work properly. Alternatively, if you publish the page first, then add the Table of Contents block, they will work correctly.
Step-by-step reproduction instructions
Create a new page
Add content, with headings, and the Table of Content block
Publish the page
View the page
Try the TOC links
Return to the editor and make a change
Update the published page
View the page
The TOC links now work
Screenshots, screen recording, code snippet
Screen.Capture.on.2022-08-20.at.10-40-21.mp4
Environment info
WordPress version 6.0.1
Gutenberg 13.9.0
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
I was able to reproduce this issue following the steps.
The tricky part is that the public URL is generated after the publish action.
When a page is added, the links of the headings are set correctly to the block's store without refreshing the edit page, but the page requires to be updated to use the public URL inside its content.
As a solution, we can remove the page URL from the links and keep only the generated hashtags.
For example, from https://example.com/sample-page/#heading-title to #heading-title.
I'm unable to find information on whether there was a reason for using the full URLs. Such page links work with hashtags only, and this solution might be sufficient.
Following the replication steps outlined in this issue, the ToC links worked for me on initial save. @Greatdane Could you confirm if this issue has been resolved or expand on the test steps?
@aaronrobertshaw, which permalink structure did you use while recording the video?
If the Plain permalink structure is used, the block works.
However, it doesn't work for me when using other permalink structures such as Post Name. In that case, the links don't include the page's name, but auto-draft is added instead.
Hi @aaronrobertshaw, it looks like you're adding the Table of Content block to a post, not a page.
Publishing a post works slightly differently than a page.
When we add a post, there is no auto-draft URL generation before publishing the page (I haven't checked why this happens, but it has to be consistent). In that case, the TOC block uses URLs like SITE_URL/?p=34. The links work because there is a redirect from SITE_URL/?p=34 to the pretty URL (WordPress handles this redirect).
On the other side, when a page is published, the TOC block uses auto-draft inside its links.
Here is a video that shows how the block behaves.
Test-TOC-block.webm
Probably, it will be better if the auto-draft URL generation issue is addressed. Initially, the links will use the plain format, which will be changed in the next content update. In that case, the links will work without pointing to a non-existing page.
Alternatively, the links can be regenerated automatically behind the scenes when a page is published. However, it doesn't seem right.
changed the title [-]Table of contents block – links don't work on initial save[/-][+]Table of contents block – links don't work on initial page save[/+]on Sep 27, 2022
But it looks like the block does not work on previews only after the page has been published. As the preview does not have the correct structure. https://bluewinddesign.com/?page_id=385 (previewed page). Clicking one of the headings in the Table of Contents block the link anchor looks like this: https://bluewinddesign.com/resume/#head-3 . It went to a 404 page.
Activity
aatanasovdev commentedon Aug 26, 2022
I was able to reproduce this issue following the steps.
The tricky part is that the public URL is generated after the publish action.
When a page is added, the links of the headings are set correctly to the block's store without refreshing the edit page, but the page requires to be updated to use the public URL inside its content.
As a solution, we can remove the page URL from the links and keep only the generated hashtags.
For example, from
https://example.com/sample-page/#heading-titleto#heading-title.I'm unable to find information on whether there was a reason for using the full URLs. Such page links work with hashtags only, and this solution might be sufficient.
aaronrobertshaw commentedon Aug 30, 2022
Following the replication steps outlined in this issue, the ToC links worked for me on initial save. @Greatdane Could you confirm if this issue has been resolved or expand on the test steps?
Screen.Recording.2022-08-30.at.2.47.08.pm.mp4
aatanasovdev commentedon Aug 30, 2022
@aaronrobertshaw, which permalink structure did you use while recording the video?
If the Plain permalink structure is used, the block works.
However, it doesn't work for me when using other permalink structures such as Post Name. In that case, the links don't include the page's name, but
auto-draftis added instead.aaronrobertshaw commentedon Sep 5, 2022
Hi @aatanasovdev, I tested with both Plain and Post Name permalink structures however I only posted a single video.
Here's a video of the table of contents working for me on initial save with the Post Name permalink setting selected.
Screen.Recording.2022-09-05.at.7.56.07.pm.mp4
aatanasovdev commentedon Sep 7, 2022
Hi @aaronrobertshaw, it looks like you're adding the Table of Content block to a post, not a page.
Publishing a post works slightly differently than a page.
When we add a post, there is no auto-draft URL generation before publishing the page (I haven't checked why this happens, but it has to be consistent). In that case, the TOC block uses URLs like
SITE_URL/?p=34. The links work because there is a redirect fromSITE_URL/?p=34to the pretty URL (WordPress handles this redirect).On the other side, when a page is published, the TOC block uses
auto-draftinside its links.Here is a video that shows how the block behaves.
Test-TOC-block.webm
Probably, it will be better if the
auto-draftURL generation issue is addressed. Initially, the links will use the plain format, which will be changed in the next content update. In that case, the links will work without pointing to a non-existing page.Alternatively, the links can be regenerated automatically behind the scenes when a page is published. However, it doesn't seem right.
aaronrobertshaw commentedon Sep 8, 2022
🤦 Sorry to waste your time. You are correct, I was on autopilot and misread the instructions.
I can confirm I'm seeing this issue when I actually test it properly.
[-]Table of contents block – links don't work on initial save[/-][+]Table of contents block – links don't work on initial page save[/+]mahnunchik commentedon Apr 18, 2023
I can confirm incorrect behaviour:
Updateall links are correct.WordPress version
6.2.0Gutenberg plugin
15.1.1felipevelzani commentedon Aug 18, 2023
I could reproduce this as well. Using Gutenberg 16.4.
This is the code on the page in case it helps: https://d.pr/n/kp52JN
annezazu commentedon Aug 24, 2023
Noting that this was brought up in the twenty fifth call for testing for the FSE Outreach Program using 16.4:
I've added it to the stabilizing the TOC issue!
Sukhendu2002 commentedon Jun 10, 2025
I attempted to reproduce this issue but was not able to—it appears to be resolved.
Tested with:
Screen.Recording.2025-06-10.at.9.19.43.AM.mp4
5 remaining items
scruffian commentedon Sep 12, 2025
Sorry closed accidentally
mikachan commentedon Oct 6, 2025
I've attempted to fix this as part of #72110.
t-hamano commentedon Oct 21, 2025
Since the ToC block itself has been punted to WP 7.0, this issue will also be punted to 7.0.
getdave commentedon Jul 16, 2026
I'm currently working on dynamically rendering the block PHP side - #43595
Once merged I will remove the editor code which serializes the headings to the ToC block markup on save.
This should resolve the auto-save problem but it will need validating and test coverage.
tyxla commentedon Sep 11, 2026
@getdave is this addressed after #80318 and #80404? If yes, let's close it, and also consider closing #70386.
Mamaduka commentedon Sep 12, 2026
Yes, this was fixed when we switched the block to server-side rendering.