Created
November 8, 2018 12:22
-
-
Save andcam/1aa7d959e3319284c9369d1d7b85f44c to your computer and use it in GitHub Desktop.
Wordpress - strip all HTML comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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