• I know there is no option to exclude heading by “class”. Is there any code snippet I can use in functions php to achieve that?

    Exclude by text is not useful in my case, it would be great to have a feature to exclude by “class”.

    Thank you.
    SJ

Viewing 3 replies - 1 through 3 (of 3 total)
  • Steven

    (@shazahm1hotmailcom)

    Please use the ez_toc_exclude_by_selector filter.

    See this example which excludes specific JetPack content by class.:

    Thread Starter Shahriyar M Jahangir

    (@shahriyarmj)

    Hi Steven,

    Thank you for the info, I might be doing something wrong, please see below.

    MY HTML
    ———-
    <body class=”type-post”>
    ….
    <h2 class=”notoc”>Hello my title to skip</h2>
    ….
    </body>

    So, I tried this in functions.php
    ———————————–

    add_filter(
    ‘ez_toc_exclude_by_selector’,
    function( $selectors ) {

    $selectors[‘notoc’] = ‘.type-post’;

    return $selectors;
    }
    );

    I was to skip all headings with the class “notoc”, But it didn’t work, I tried the reverse ($selectors[‘type-post’] = ‘notoc’;), didn’t work either.

    Which class should I add as the key and which as the value? I am misunderstanding something here.

    Thank you.
    //SJ

    Steven

    (@shazahm1hotmailcom)

    Ata glance this looks correct. Use var_dump or whatever to make sure the filter is being loaded/used. The most common issue with WordPress filters is they not being added in time to be applied.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude by Class programatically?’ is closed to new replies.