Skip to content

Instantly share code, notes, and snippets.

@Jany-M
Created August 1, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jany-M/b86c164cc5da14d7007a3abb34197068 to your computer and use it in GitHub Desktop.
Save Jany-M/b86c164cc5da14d7007a3abb34197068 to your computer and use it in GitHub Desktop.
[WP] Check content for h3 tags
<?php
// Check content for h3
$doc = new DOMDocument;
$doc->loadHTML(get_the_content(get_the_ID()));
$titles = $doc->getElementsByTagName('h3');
//var_dump($titles); // int
// Prints the content
if( !is_null($titles->item(0)) ) {
echo $titles->item(0)->nodeValue;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment