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:
<?php /** * 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() { ob_start("wpster_callback"); } function wpster_buffer_end() { ob_end_flush(); } ?>
The conditional CSS class like
<!-- [if lt IE 10]>
won’t be removed.