I want to display the table of contents only for specific blog posts
On this page, we'll introduce how to hide the table of contents for specific blog posts. This method can also be applied to product pages and collection pages.
There are 3 ways to hide the table of contents:
1. Using Meta Fields.
It's possible to hide the table of contents by setting the value of the following metafield for specific content.
[Meta Field Value to Hide Table of Contents]
Name: Any text
Namespace and Key: table_of_contents.hidden
Type: number_integer
Value: 1
How to Create Meta Field Definitions:
Go to Settings, then Custom Data
Select "Blog Posts"
3. Click Add definitions
Fill in each item of the definition:
Name: Any text
Namespace and Key: table_of_contents.hidden
Type: Integer (number_integer)
Click "Save"
2. Creating a "without table of contents" Blog Post Template.
This is a method to create a "Blog Post Template Without Table of Contents" in addition to the "Default Blog Post Template."
Add the "Table of Contents" app to the "Default Blog Post Template," but don't add it to the "Blog Post Template Without Table of Contents." By applying the "Blog Post Template Without Table of Contents" to specific blog posts where you don't want to display a table of contents, you can hide it for those particular posts.
Note: This method is only possible with Online Store 2.0 themes.
How to Create a Blog Post Template Without a Table of Contents:
Open the Theme Editor
Select "Blog Post" from the dropdown menu at the top center of the screen
Click "Create Template"
Enter a name of your choice
Click "Create Template"
7. Disable or remove the table of contents app
8. Click save
How to Apply the "Blog Post Template Without Table of Contents" to Posts Where You Don't Want to Display a Table of Contents:
Access the blog post where you don't want to display a table of contents
Select the "Blog Post Template Without Table of Contents" from the theme templates
Click "Save"
3. Do not use the headings set in "Headings to be used" in the blog post.
RuffRuff Table of Contents will not display a table of contents if none of the headings used in the table of contents exist in the blog post.
For example, if you have set up your blog post to use Heading 2 (h2) and Heading 3 (h3) for the table of contents, if you create your blog post avoiding Heading 2 (h2) and Heading 3 (h3), the table of contents will not be displayed.