Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1.                     $content = get_the_content();
  2.  
  3.                     $dom = new DomDocument();
  4.                     $dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
  5.  
  6.                     $xpath = new DOMXPath($dom);
  7.                     $heads = $xpath->query('//h1|//h2|//h3|//h4|//h5|//h6');
  8.  
  9.                     echo '<ul>';
  10.                     foreach ($heads as $tag) {
  11.                         echo '<li><a href="#'. sanitize_title($tag->nodeValue) .'" title="'. $tag->nodeValue .'">'. $tag->nodeValue .'</a></li>';
  12.                     }
  13.                     echo '</ul>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement