• Resolved grebfar

    (@grebfar)


    Hi there Dev. Thanks for your great little TOC tool. I need your quick assistance to exclude headings from a Gutenberg Block of Related Posts.

    My theme is from Genesis (a reasonably large theme provider) and comes with a Gutenberg Block called Mai Grid that is used to show Related Posts. The Block pulls in the Related Post Headings and displays them as <H3>. Easy Table of Contents then picks these headings up and shows them in the TOC. This behavior should not occur.

    With your existing customizations I can only choose to exclude all H3 headings and this would defeat the purpose of the TOC. So I ask for what I hope is a small update.

    Could you please exclude the “Mai Grid” Block class from displaying in the TOC? This should resolve the issue for me and other Genesis users.

    Below is the page inspection of the Related Posts block which slows the class name and the H3 headings that are pulled in.

    View post on imgur.com

    Alternatively, you could add functionality to the settings so that users can specify a class to be excluded. This would solve the greater issue, as I have seen other related reports to this problem for other plugins.

    Thanks for taking the time to do what you do.

    Greb

Viewing 1 replies (of 1 total)
  • Thread Starter grebfar

    (@grebfar)

    OK I have managed to resolve this and I am going to step you through it as this is a general solution that anybody can use.

    If you have a plugin that displays related posts (or similar) and the headings are getting picked up in the TOC, this is how you can exclude the headings from the table of contents.

    1. Identify the name of the block that holds the headings you don’t want displayed. To do this, right click and “inspect element”. You will need to find the class name for the element. In my case it was called “mai-grid”.

    2. Go to your Theme Editor and Edit the functions.php file

    3. Add the following code


    add_filter(
    ‘ez_toc_exclude_by_selector’,
    function( $selectors ) {
    $selectors[‘MAI-GRID’] = ‘.MAI-GRID’;
    return $selectors;
    }
    );

    4. Replace MAI-GRID with the name of class name of the block that is displaying the headings you don’t want to see

    Done.

    Easy Table of Contents now correctly displays only headings from the article, and not from the related posts plugin at the end of the content.

    Hope someone finds this useful.

    • This reply was modified 2 years, 5 months ago by grebfar.
Viewing 1 replies (of 1 total)
  • The topic ‘Exclude Headings in Related Posts Block’ is closed to new replies.