Doesn’t work anymore
-
After some recent updates I noticed this no longer works anymore. I had the auto-embed feature overridden to use the widget/block instead. But the widget no longer works in WordPress and there is no actual Block. I removed the widget and tried to use a shortcode like this in my template: [toc label=”Table of Contents” heading_levels=”1,2,3,4,5″]
It doesn’t do anything either. What happened to this plugin? Do the shortcodes not work at all?
-
Hi @gmariani405 ,
Thanks for reaching out!
Sorry for the confusion here. Short answer: the shortcode still works, but only inside post content, and the plugin has never had a block. Let me walk through each piece.
The block: Table of Contents Plus doesn’t include a Gutenberg block, and it never has. The sidebar option has always been the classic “TOC+” widget.
The widget: Classic widgets only show up under Appearance > Widgets (wrapped in a “Legacy Widget” block), and only when your active theme still registers classic widget areas- https://a.supportally.com/i/wYn6cj. If your site moved to a block theme (one that uses the Site Editor), those widget areas and the whole Widgets screen go away, so the widget has nowhere to render. That comes from WordPress and the theme, not from the plugin. Which theme are you running?
The shortcode:
[toc]only works inside the content of a post or page. The shortcode itself just leaves an invisible placeholder, and the plugin swaps in the real table while WordPress renders the post content. A theme template never goes through that step, so pasting the shortcode there outputs nothing. If you want the table in a template, the plugin ships a PHP helper for exactly that:<?php echo toc_get_index(); ?>Please also check your settings after the recent update. The July release rebuilt the settings screen, which now lives in its own “ToC+” menu in the admin sidebar. We’ve seen heading level selections come out reset after an update for some users, and with no heading levels selected the plugin stops generating a table anywhere, including in the widget. In ToC+ > Settings, on the Display tab, please confirm Posts and Pages are checked under “Auto-insert for”, the “Heading levels” boxes (h1 to h6) are still ticked under Headings, and take a look at the “Minimum headings” condition. It’s usually set to “4 or more headings“, so the table only appears on content with at least that many. Then save once, even if everything looks right.
To test, add
[toc]directly into the content of a page with at least 4 headings and check the front end. Here’s a quick screencast showing how that looks:https://a.supportally.com/v/LIvHZt
If it still doesn’t show after the steps above, let me know your theme name and WordPress version and we’ll take a closer look.
Hello @aurangajeb ,
So the reason I mentioned the block is that’s what it says in the plugin:
Widget & Block
Widget/block only: When enabled, the table of contents is not inserted into the content for the selected post types — it only appears where you add the widget or block.Since it mentions a block, I assumed there was a block feature broken. But you’re saying this is just incorrect then.
As for the theme, I’m running Twenty Twenty-Three using FSE which worked up until a few months ago. As for your tip “If you want the table in a template, the plugin ships a PHP helper for exactly that” – I can’t use that in the FSE. I was using the widget before that but the widget stopped working. In the template editor i get this:
“The “toc-widget” block was affected by errors and may not function properly. Check the developer tools for more details.”
It sends a POST to
/wp-json/wp/v2/widget-types/toc-widget/encode?_locale=userwith this as the data:{"instance":{"encoded":"YT...7fQ==","hash":"1a...021"},"number":1,"form_data":nullWhich the server responds back with a 400:
{"code":"rest_invalid_widget","message":"The provided instance is malformed.","data":{"status":400}}Finally, adding a [toc] directly to the page works, but that’s not helpful when i need it on every page of my website. Having it in the theme is the correct place for it.
Hi @gmariani405 ,
You’re right about that settings text. It does say “widget or block”, but the plugin doesn’t currently ship a block. I’ve reported the wording to our developers. Sorry for the confusion it caused.
The 400 error you captured isn’t coming from TOC+. WordPress signs a Legacy Widget block’s saved data with your site’s security keys (the salts in
wp-config.php), and “The provided instance is malformed” means that signature no longer matches. That happens when the keys changed after the block was saved: a site migration, a backup restore, or a security plugin rotating the keys. Did anything like that happen around the time it broke? The plugin update is most likely a coincidence, and[toc]working in your content confirms the plugin itself is fine.To get the table on every page:
Option 1, no code: re-enable auto-insert under ToC+ > Settings > Display tab (“Auto-insert for” > Posts and Pages). The table appears automatically at your chosen Position.
Option 2, in your template: Legacy Widget blocks aren’t supported inside Site Editor templates, so use a small shortcode instead:
- Keep Posts and Pages checked under “Auto-insert for”.
- On the Advanced tab, under “Widget & Block“, enable “Widget/block only” and select the same post types. This keeps the heading anchors in your content but takes the table out of it. Here’s where it is: https://a.supportally.com/i/udEeFS
- Add this PHP snippet with the free WPCode (https://wordpress.org/plugins/insert-headers-and-footers/) plugin:
add_shortcode( 'toc_plus_template', function () {
if ( ! function_exists( 'toc_get_index' ) || ! is_singular() ) {
return '';
}
$items = toc_get_index( '', '', true );
if ( ! $items ) {
return '';
}
return '<ul class="toc_widget_list no_bullets">' . $items . '</ul>';
} );- In the Site Editor, add a Shortcode block to your template with
[toc_plus_template]in it.
I’ve tested this setup on a block theme: the table follows your display rules, picks up the plugin’s styling, and the links jump correctly.
Let me know how it goes.
Hey @gmariani405,
I updated the description in the latest update. I’ll also continue looking into support for FSE themes and potentially a block in the future.
@aurangajeb Thanks for the explanation, and that does make sense. That is unfortunate about the necessity to create a shortcode in order to trigger the plugin at the right time. Thank you for the workaround though.
@arnaudbroes Thanks for taking care of that. I look forward to better integration with FSE themes and Gutenberg in general.
You must be logged in to reply to this topic.