Skip to content

Instantly share code, notes, and snippets.

@danemorgan
Created November 29, 2017 14:15
Show Gist options
  • Save danemorgan/d16c84592e0b5dc70688742136db211e to your computer and use it in GitHub Desktop.
Save danemorgan/d16c84592e0b5dc70688742136db211e to your computer and use it in GitHub Desktop.
Have to loop backward through the DOMnodeList to delete nodes
$comment_anchors = $dom_comment->getElementsByTagName( 'a' );
for ( $i = $comment_anchors->length; --$i >=0; ) :
$comment_anchor = $comment_anchors->item( $i );
if ( trim ( $comment_anchor->nodeValue ) === '' ) :
$comment_anchor->parentNode->removeChild( $comment_anchor );
endif;
endfor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment