Hide table of contents if no headings

tdrayson

On SnippetClub, I use a table of contents in the sidebar. However, on some older posts, I don’t have any headings on the page. This causes a blank space to be rendered. I wanted a way to hide the whole table of contents container if I don’t have any headings.

1.The code

Add the code below into your functions.php or code snippet plugin.

Members content only

Become a SnippetClub member to gain instant access to this tutorial plus tons more premium content.

Already a member? Log in below.

Login Form

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.

Newsletter

🔒I won't send you spam, I promise