Skip to content

Instantly share code, notes, and snippets.

@andcam
Created November 8, 2018 12:22
Show Gist options
  • Save andcam/1aa7d959e3319284c9369d1d7b85f44c to your computer and use it in GitHub Desktop.
Save andcam/1aa7d959e3319284c9369d1d7b85f44c to your computer and use it in GitHub Desktop.
Wordpress - strip all HTML comments
class ljxdmStripComments
{
public function __construct() {
add_action('get_header', array($this, 'start'), 100);
add_action('wp_footer', array($this, 'end'), 100);
}
private static function strip($html) {
return preg_replace('/<!--(.|\s)*?-->/','',$html);
}
public static function start() {
ob_start(array($this, 'strip'));
}
public static function end() {
ob_end_flush();
}
}
// PHP 5.4 required
new ljxdmStripComments;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment