[WP]: How to Generate a Table of Contents for Posts

Table of Contents for Posts

for Functions.php [php] // Inject the TOC on each post. add_filter(‘the_content’, function ($content) { global $tableOfContents; $tableOfContents = " <div class=’h5′> Table of Contents <span class=’toggle’>+ show</span> </div> <div class=’items’> <div class=’item-h2′> <a href=’#preface’>Preface</a> </div> "; $index = 1; // Insert the IDs and create the TOC. $content = preg_replace_callback(‘#<(h[1-6])(.*?)>(.*?)</\1>#si’, function ($matches) use (&$index, &$tableOfContents)… Continue reading [WP]: How to Generate a Table of Contents for Posts