Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $content = get_the_content();
- $dom = new DomDocument();
- $dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
- $xpath = new DOMXPath($dom);
- $heads = $xpath->query('//h1|//h2|//h3|//h4|//h5|//h6');
- echo '<ul>';
- foreach ($heads as $tag) {
- echo '<li><a href="#'. sanitize_title($tag->nodeValue) .'" title="'. $tag->nodeValue .'">'. $tag->nodeValue .'</a></li>';
- }
- echo '</ul>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement