regex delete html comments in wordpress
How do I delete all comments in wordpress, after the tag </html>
?
example
</body></html> <!-- bla bla --><!-- more bla bla --><!--and more bla bla -->
r开发者_如何学Pythoneplace in
</body></html>
I would one function to be included in my function.php theme.
thank you
i found this:
If you put this in your functions.php, it will delete all the HTML comments that are in your code.
function callback($buffer) {
$buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer);
return $buffer;
}
function buffer_start() {
ob_start("callback");
}
function buffer_end() {
ob_end_flush();
}
add_action('get_header', 'buffer_start');
add_action('wp_footer', 'buffer_end');
精彩评论