Remove all comments in source code

How can I remove all comments from source code?

Whether for performance reasons (less lines of code) or confidentiality reasons (hiding commented lines or avoiding the flashy signature of a plugin), it is interesting to mask the comments of the source code of your pages (the HTML rendering, not the source code of your templates).

To do this, simply add this code to your functions.php file:

 * Remove all comments in source code
add_action('get_header', 'wpster_buffer_start');
add_action('wp_footer', 'wpster_buffer_end');
function wpster_callback($buffer) {
    $buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer);
    return $buffer;
function wpster_buffer_start() {
function wpster_buffer_end() {

The conditional CSS class like

<!-- [if lt IE 10]>

won’t be removed.

Submit a Comment

Your email address will not be published. Required fields are marked *