add_filter TOC with add_shortcode

#42937
  • Resolved Dinhs
    Rank Math free

    Hi,

    I have add_shortcode get a TOC content

    function create_dc_toc( $atts, $content = null ) {
        $output .= '<div id="kc-elm dc_toc"><p class="dc_toc_title">Header Article</p><a href="#" class="toggle" data-label="Show">Hide</a><ul id="toc"></ul></div>';
        return $output;
    }
    add_shortcode( 'dc_toc', 'create_dc_toc' );

    How to add_filter rank_math for my shortcode.

    i try

    add_filter('rank_math/researches/dcrm_toc', function ($dcrm_toc) {
        $dcrm_toc = do_shortcode('[dc_toc]');
        return $dcrm_toc;
    });

    but not vaild Use Table of Content to break-down your text.

    Any idea for help me. Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Th filter that you have mentioned only works when adding TOC from third party plugins. I can suggest that you use one of the following snippets to disable this test.

    If you are using the classic editor to edit your post, please add the following code snippet to your theme’s 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 );

    If you are using the block editor, please add this code instead:

    add_filter( 'rank_math/researches/tests', function( $tests, $type ) {
    	unset( $tests['contentHasTOC'] );
    	return $tests;
    }, 10, 2 );

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Dinhs
    Rank Math free

    @Michael Davis

    Thanks for support, but i try in function.php (i use Classic Editor )

    add_filter( 'rank_math/researches/tests', function( $tests, $type ) {
    	
    	unset($tests['content-readability']['contentHasTOC']);
    
    	$tests['basic']['keywordInMetaDescription']['score'] = 4;
    
        return $tests;
    }, 10, 2 );

    but my site Content Readability note is Use Table of Content to break-down your text.

    How to debug?

    Thanks!

    • This reply was modified 5 years, 7 months ago by Dinhs.
    Dinhs
    Rank Math free

    unset( $tests['contentHasTOC'] ); working for me (i user a builder element). But seo-score in edit post not equal in all Post? My score in edit post = 100 but in all Post = 93.

    Thanks.

    Dinhs
    Rank Math free

    I think my cache page. Now all bug be processed. I have control this Plugin.

    Good Plugin. Thanks 🙂

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘add_filter TOC with add_shortcode’ is closed to new replies.