-
Hello all,
I am getting an error in the Edit Snippet section on my FAQ page that I’m currently working on:
Use Table of Content to break-down your text.
As you can see on the page, there is a Table of Contents at the top before the main content, so I don’t understand why this error is happening?
https://reclaimdesign.org/home-decor-products-faq.htmlThanks for your help.
Michael.
-
Hi Michael,
​We only detect Table of Contents if you are using one of these plugins to add a table of contents section.
​
https://rankmath.com/kb/score-100-in-tests/#table-of-contents
​
​Unfortunately, there is no other way to look for a Table of Contents section other than to look for pre-installed ToC plugins like the ones listed above. You also use the filter provided in the above link to manually add your plugin to the compatibility list (or ask your ToC plugin provided to add it to their plugin)
​
You can also use this code in your theme’s functions.php file to manually tell Rank Math that you are already using a Table of Contents and to pass that test.
​
https://pastebin.com/RUdAkgMm
​
​Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.Thank you Todd. The ToC code is of my own doing, so no plugin as such. I followed the pastebin link but it gives an Error 502
I’ve accessed the pastebin link now – must have been a glitch. I created a code snippet with the php given, saved, activated and cleared cache, but for some reason the ToC test still shows up as failing
Hi Michael,
Thank you for the reply.
Could you please share more info on this statement: The ToC code is of my own doing how have you set this up?
As a workaround, you can also disable this test by using the following code snippet on your functions.php file:
/** * Rank Math snippet to disable 'titleHasNumber' & 'contentHasTOC' tests. * * @param array $tests Array of tests with score * @param string $type Object type. Can be post, user or term. */ add_filter( 'rank_math/researches/tests', function( $tests, $type ) { unset($tests['content-readability']['contentHasTOC']); $tests['basic']['keywordInMetaDescription']['score'] = 4; return $tests; }, 10, 2 );
I hope this info helps. Thank you.
Hi Michael,
Sure, I set up a js file with:
var coll = document.getElementsByClassName("collapsible"); var i; for (i = 0; i < coll.length; i++) { coll[i].addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.maxHeight){ content.style.maxHeight = null; } else { content.style.maxHeight = content.scrollHeight + "px"; } }); }
And set up the following CSS:
/*-------------------------------------------------------------- # Table of Contents --------------------------------------------------------------*/ button.collapsible { background-color: #539c22; border: 0; border-top-left-radius: 10px; border-top-right-radius: 10px; color: #ffffff; cursor: pointer; font-family: 'Carrois Gothic', sans-serif; font-size: 20px; line-height: 1.3em; outline: none; padding: 15px 20px; text-align: left; text-transform: uppercase; transition: opacity .3s ease-in-out; -moz-transition: opacity .3s ease-in-out; -o-transition: opacity .3s ease-in-out; -webkit-backface-visibility: hidden; -webkit-transition: opacity .3s ease-in-out; width: 100%; } .collapsible:hover { opacity: .7; } .collapsible:after { color: #ffffff; content: '\002B'; font-size: 36px; float: right; margin-left: 5px; } .active:after { content: "\2212"; } ul.content { border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-bottom: 1px solid #d0d0d0; border-left: 1px solid #d0d0d0; border-right: 1px solid #d0d0d0; border-top: 0; box-shadow: 0 0 0; margin: 0; max-height: 0; overflow: hidden; padding: 0 20px; text-align: left; transition: max-height .3s ease-out; } li.toc { list-style: square; margin-left: 15px; padding: 10px 0 0 10px; } ul li.toc:last-child { padding-bottom: 10px; }
And HTML on a per page basis:
<button class="collapsible">Table of Contents</button> <ul class="content"> <li class="toc"><a href="#1">Large Lazer Etched Boxes made from Reclaimed Wood</a></li> <li class="toc"><a href="#2">Small Lazer Etched Boxes made from Reclaimed Wood</a></li>
I ran the code you posted from the Code Snippets plugin:
/** * Rank Math snippet to disable 'contentHasTOC' tests. * * @param array $tests Array of tests with score * @param string $type Object type. Can be post, user or term. */ add_filter( 'rank_math/researches/tests', function( $tests, $type ) { unset($tests['content-readability']['contentHasTOC']); $tests['basic']['keywordInMetaDescription']['score'] = 4; return $tests; }, 10, 2 );
But I could still see the ToC test within the RankMath area of the page edit
“Use Table of Content to break-down your text” is still visible on a page with a ToC
Hi Michael,
Thank you for the reply.
It is not possible to detect the custom ToC using the code my colleague shared above but the last code should be able to work. I have tested this code on my end and it works perfectly.
Could you please register the code from within the functions.php of your child theme and check if the results will be different?
Thank you.
Hi Michael, the code looks identical. The only difference I can see is in the comments. I don’t have a child theme as far as I am aware
Original:
/** * Rank Math snippet to disable 'contentHasTOC' tests. * * @param array $tests Array of tests with score * @param string $type Object type. Can be post, user or term. */ add_filter( 'rank_math/researches/tests', function( $tests, $type ) { unset($tests['content-readability']['contentHasTOC']); $tests['basic']['keywordInMetaDescription']['score'] = 4; return $tests; }, 10, 2 );
Your new code:
/** * Rank Math snippet to disable 'titleHasNumber' & 'contentHasTOC' tests. * * @param array $tests Array of tests with score * @param string $type Object type. Can be post, user or term. */ add_filter( 'rank_math/researches/tests', function( $tests, $type ) { unset($tests['content-readability']['contentHasTOC']); $tests['basic']['keywordInMetaDescription']['score'] = 4; return $tests; }, 10, 2 );
The only change I see is:
* Rank Math snippet to disable 'contentHasTOC' tests.
Changes to:
* Rank Math snippet to disable 'titleHasNumber' & 'contentHasTOC' tests.
Screengrab of my code snippet within WP dashboard:
https://www.dropbox.com/s/cwswkigzuoysoox/screen-code-snippet.jpg?dl=0
Hi Michael,
We are sorry but that code doesn’t work on Gutenberg since a previous update.
We are working on an update to make it work though.
We would appreciate your patience in the meantime.
Thank you.
Hi Todd,
This comes across as unhelpful/abrasive:
Michael, I would request you to not hijack other’s posts. I have re-opened your previous ticket so please free to followup there.
I commented on a post relating to the issue I described in a previous ticket that was never resolved by Rankmath:
The ticket I opened was closed by RankMath, so it was not possible for me to continue on the ticket.
I would request you please give helpful responses that resolve the issues I’ve posted about (then I won’t have to post about the issues anymore – happy days for all of us trust me) instead of either not reading them or fobbing them off.
Many thanks.
Michael.
Hi,
I am sorry about that.
Please use this code in the theme’s functions.php file to tell Rank Math that you are already using a ToC:
/** * Filter to add plugins to the TOC list. * * @param array TOC plugins. */ add_filter( 'rank_math/researches/toc_plugins', function( $toc_plugins ) { $toc_plugins['seo-by-rank-math/rank-math.php'] = 'Plugin Name'; return $toc_plugins; });
That should do the trick.
I see the topic was closed by our bot.
If this doesn’t fix the issue, please open a new ticket and paste the link to this topic in your new post.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hi Todd, that code worked this time. Thank you.
Hi Michael.
I am glad that this did the trick 🙂
Feel free to contact us for any other questions. 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 ‘Content Readability Error’ is closed to new replies.