|
/*--------------------------------------------*/ |
|
/* Replace H Tags |
|
/*--------------------------------------------*/ |
|
|
|
function get_inner_html( $node ) { |
|
$innerHTML= ''; |
|
$children = $node->childNodes; |
|
foreach ($children as $child) { |
|
$innerHTML .= $child->ownerDocument->saveXML( $child ); |
|
} |
|
return $innerHTML; |
|
} |
|
|
|
function my_added_page_content ( $content ) { |
|
if ( is_page() ) { |
|
|
|
$dom = new DOMDocument(); |
|
// $dom->loadHTML($content); |
|
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content); |
|
|
|
$xpath = new DOMXPath($dom); |
|
|
|
$items = array('h1','h2','h3','h4','h5'); |
|
|
|
foreach ($items as $item) { |
|
|
|
// $tags = $dom->getElementsByTagName($item); |
|
$tags = $xpath->evaluate("//".$item); |
|
|
|
foreach ($tags as $tag) { |
|
|
|
$style = $tag->getAttribute('style'); |
|
$class = $tag->getAttribute('class'); |
|
// $newtag = $dom->createElement('div', htmlspecialchars($tag->nodeValue)); |
|
$newtag = $dom->createElement('div', get_inner_html($tag)); |
|
|
|
$newtag->setAttribute('class', $item.' '.$class); |
|
if($style) $newtag->setAttribute('style', $style); |
|
$tag->parentNode->replaceChild($newtag, $tag); |
|
} |
|
} |
|
|
|
$dom = $dom->saveHTML(); |
|
// return $dom; |
|
return htmlspecialchars_decode($dom); |
|
|
|
} else { |
|
return $content; |
|
} |
|
} |
|
add_filter( 'the_content', 'my_added_page_content'); |