# Onebox sieht auf Discourse-Kommentaren (unter WP-Beitrag) schrecklich aus

**URL:** https://meta.discourse.org/t/onebox-looks-horrible-on-discourse-comments-below-wp-post/78364
**Category:** WordPress
**Created:** [18. Januar 2018 um 13:20 UTC](https://meta.discourse.org/t/onebox-looks-horrible-on-discourse-comments-below-wp-post/78364 "2018-01-18T13:20:04Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [14. Februar 2018 um 17:13 UTC](https://meta.discourse.org/t/onebox-looks-horrible-on-discourse-comments-below-wp-post/78364/8 "2018-02-14T17:13:15Z")

</div>

Something like this should work to remove oneboxes from comments. It’s assuming that the `libxml` extension is loaded on your server. (It probably is.)

```php
add_filter( 'wpdc_comment_body', 'wpdc_custom_comment_body' );
function wpdc_custom_comment_body( $content ) {
	// Allows parsing misformed html. Save the previous value of libxml_use_internal_errors so that it can be restored.
	$use_internal_errors = libxml_use_internal_errors( true );

	$doc = new \DOMDocument( '1.0', 'utf-8' );
	$doc->loadHTML( mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' ) );

	$finder = new \DOMXPath( $doc );
	$oneboxes = $finder->query( "//*[contains(@class, 'onebox')]");
	foreach( $oneboxes as $onebox ) {
	    $onebox->parentNode->removeChild( $onebox );
    }

	// Clear the libxml error buffer.
	libxml_clear_errors();
	// Restore the previous value of libxml_use_internal_errors.
	libxml_use_internal_errors( $use_internal_errors );

	$parsed = $doc->saveHTML( $doc->documentElement );

	// Remove DOCTYPE, html, and body tags that have been added to the DOMDocument.
	$parsed = preg_replace( '~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $parsed );

	return $parsed;
}

```

The Discourse plugin uses `DOMDocument` to fix relative links that are returned from Discourse. That code is here: [https://github.com/discourse/wp-discourse/blob/master/templates/template-functions.php#L71](https://github.com/discourse/wp-discourse/blob/master/templates/template-functions.php#L71)

---

_[View the full topic](https://meta.discourse.org/t/onebox-looks-horrible-on-discourse-comments-below-wp-post/78364)._
