php-html-parser
php-html-parser copied to clipboard
Retrieved changed DOM HTML - missing <script type="json+ld"> tags
Hi!
I'm working on a WordPress project where I need to replace all alt attributes for tags if there is no alt, or alt attribute is empty.
So I have this filter function:
`
function replace_empty_alt_tags($content){
global $post;
$dom = new Dom;
$dom->loadStr($content);
$imageNodes = $dom->find('img');
foreach ($imageNodes as $node){
if ( empty($node->getAttribute( 'alt' )) ){
$node->setAttribute( "alt", get_the_title( $post->ID )." | CANNOVIA" );
}
}
$content = $dom->__toString();
return $content;
} `
It works well, but it removes Schema markup made with LD-JSON tags. So it's missing it. Maybe I retrieve DOM HTML content in a wrong way (at the end)? Or this is really a bug?