- 
		
My table of contents is too long. I want to make it collapsible and I want it to be closed when the visitor reaches the post, and only when he clicks on it – it will open.
How can I do it? Is there any code to add?
Thank you! π 
- 
		
			
				
Hello,
Thank you for contacting us and bringing your concern to our attention.
Iβm sorry to inform you that, by default, there is no option available for that but if you want you can use the following customize CSS on your site to make your ToC collapsable:
#rank-math-toc{ position:relative; } #rank-math-toc h2 { background: #f1f2f6; padding: 10px 12px 10px 18px; cursor: pointer; font-size: 18px !important; font-weight: normal !important; position:relative; margin-bottom: 0; } #rank-math-toc h2:before { display:inline-block; content: ""; width: 0; height: 0; border-style: solid; border-width: 6px 0 6px 12px; border-color: transparent transparent transparent #000000; margin-right: 8px; } #rank-math-toc nav{ padding: 10px 10px 0px 10px; max-height: 0; overflow:hidden; } #rank-math-toc input:checked+h2~nav { max-height: 100vh; overflow:visible; }Hereβs a guide you can follow to add this custom CSS on your site:
https://www.wpbeginner.com/plugins/how-to-easily-add-custom-css-to-your-wordpress-site/Once done, add this filter to your site: https://pastebin.com/jLTDeAWw
Here is how to add a filter to your site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/This should make the TOC collapsable
Let us know how it goes. Looking forward to helping you.
Thank you.
Hi, thank you very much for your help!
It seems to have succeeded in making the table of contents collapsible (as you can see here – https://ibb.co/X2Y08W2), but now when I click on it – it doesn’t open… How can I solve this?
Thank you! πHello,
Can you please confirm if you’ve applied the filter code I’ve shared above?
After applying the custom CSS, please add this filter to your website to make your Table of Contents collapsable: https://pastebin.com/jLTDeAWw
Here is how you can add this filter to your website:
https://rankmath.com/kb/wordpress-hooks-actions-filters/Let us know how it goes. Looking forward to helping you.
Thank you.
Did I follow the instructions correctly? (in my last reply)
Thanks πHello,
Everything looks fine in terms of settings and code.
Just to be double sure, is your child theme active instead of parent theme? If yes, please share the website URL, so that we can look into the issue further.
Looking forward to helping you.
Thank you.
Oh, I didn’t know the child theme should be active…
I tried activating the child theme now and the site crashed, and I couldn’t even log into my admin panel…
Only after I deleted the child theme in my cpanel, the site and admin panel were live back…
What can I do?
Thanks πHello,
You can create the “rank-math.php” file in the main theme as well or you can use plugin like https://wordpress.org/plugins/code-snippets/.
I would suggest using the plugin and add the code given above.
Let us know how it goes.
Looking forward to helping you.
Thank you
I copied the file to the main theme, and the site crashed again as you can see here – https://ibb.co/yB5VmvJ
Only after I deleted it from there it came back…
Why do you think it’s happening? Is there a way to make it work besides installing code snippets?(I prefer not to use the code snippets plugin if possible, as this plugin slows down my sites…)
Thank you! π
Hello,
Please try to add
<?phpat the beginning of yourrank-math.phpfile.If the issue still persists, then we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
Looking forward to helping you.
Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.
 
The ticket ‘How to make Rank Math table of contents collapsible?’ is closed to new replies.