Strip HTML comments from plugins in header/footer

This is possible. I have tested it on my own server, but it might be better to just remove the comments yourself, or put them as php comments regardless.

I only demo’d this with header.php, and used the code from this page to assist me.

First of all, take the entire contents of your header.php (or whatever other file you want to remove comments from) and put them into a new file like header2.php – call it whatever you want, just remember it for later.
Then, in your now empty header.php, put the following php code:

<?php
// Remove unwanted HTML comments
ob_start();
include 'header2.php';
$newheader = ob_get_clean();
remove_html_comments($newheader);
function remove_html_comments($content) {
    echo preg_replace('/<!--(.|\s)*?-->/', '', $content);
}
?>

Remember: If you named your new file something other than header2.php, change it’s name accordingly on line 4 of the code!

It stores the response from your old header.php in an output buffering, then runs the nifty code that we got from the post I linked to earlier, and echoes the output.

This produced the desired affect, and the echoed code still showed stuff like what page I was on, etc – enjoy! (Ps. Use at own risk)

As suggested by another member, you could just name header2.php to something along the lines of header-custom.php which in effect lets you use get_header(custom), instead of having to use an output buffer (I think… not too sure, haven’t tested). This is probably a more correct method of naming, at the very least it might help if you’re making a theme to sell it.