Generate table of contents from h1-h6 tags.
Run composer.
comopser require kunoichi/toc-generatorAnd include autoloader.
require __DIR__ . '/vendor/autoload.php';W.I.P
In your functions.php
// Register TOC.
// If you have theme option for it,
// detect conditions.
add_action( 'init', function() {
$parser = new Kunoichi\TocGenerator\WpParser();
$parser->set_title( __( 'Table of Contents', 'your-theme' ) );
} );And render TOC where you want(e.g. In your singular.php).
You need $post_id to render TOC.
In this case, get_queried_object_id() is used.
Kunoichi\TocGenerator\WpParser::render( get_queried_object_id() );