• Resolved sjc999

    (@sjc999)


    Is it possible to exclude content by CSS class? I have dynamic content I don’t want in TOC, so the mechanism of exclusion by text matching won’t work. The class could be applied to the h tag directly, or to a container like a div that contained the h tag. THanks

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

    (@shazahm1hotmailcom)

    This is possible but only by adding a filter (PHP code).

    Here’s a link to an actual filter you can use as reference to create your own.

    You would change this line to suit

    $selectors['elegant-themes-bloom'] = '.et_bloom_below_post';

    Example:

    $selectors['your-div-class-name'] = '.your-div-class';

    I hope this helps!

    Thread Starter sjc999

    (@sjc999)

    Thanks.
    Presuming .xxx is the class, is there any significance to the $selectors[‘xxx’] part? IOW, if I’m not using Elegant Themes, could I just add the class “et_bloom_below_post” to my div since it is already in the the plugin, and will mean nothing to my own theme? Or am I missing something? Thanks

    Steven

    (@shazahm1hotmailcom)

    You can ignore anything that mentions ET, the link was an example of such a filter to be used as a pattern for your own custom filter.

    An example, presuming the .xxx class.

    add_filter(
    	'ez_toc_exclude_by_selector',
    	function( $selectors ) {
    
    		$selectors['my-xxx-class-filter'] = '.xxx';
    
    		return $selectors;
    	}
    );
    Thread Starter sjc999

    (@sjc999)

    One more question. Does the h tag need to be a direct descendant of the class, or will it work for any descendant? Thanks

    Steven

    (@shazahm1hotmailcom)

    It should work for any descendant of the class.

    The way it works is there is a HTML parser which “reads” the post looking for all selectors passed by the filter. The parser grabs the entire node and searched that node for any headings. When one is found it is added to the excluded headings list (like which can be set globally or per post) and then skips those when creating the TOC items.

    Thread Starter sjc999

    (@sjc999)

    Thanks. All working now.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Exclusion of headings by CSS class’ is closed to new replies.