<?php

/**
 * Native post index
 */

function auto_index(){?>

<script type="text/javascript" id="auto-index" async defer>

      function indexContent(context){

      var container = document.querySelector(context);

      table = document.getElementById("index-table");
      var titles = Array.from(container.querySelectorAll("h1, h2, h3, h4, h5, h6"));

      for (var i = 0, l = titles.length; i < l; i++) {

        var tit = titles[i];

        tit.setAttribute("id", 'title-' + i);

        var node = document.createElement("LI");                 
        var link = document.createElement("A");
        var textnode = document.createTextNode(tit.textContent);

        link.appendChild(textnode);
        link.setAttribute("href", '#title-' + i);
        node.appendChild(link);

        table.appendChild(node);

      }
    }

    // Just drop here your element, class or ID
    indexContent(".post-entry-content");

</script>

<?php }

add_action( 'create_index', 'auto_index' );

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.