When viewing the source of your WordPress website, you may notice that there are a lot of HTML comments sitting there for no reason. HTML comments are not visible on the actual page and in some cases are there to help developers but are no longer needed within the code. A good plugin to use to help cleanup your site’s coding and remove any HTML comments is Head Cleaner, this plugin also gives you the option to remove any unwanted meta tags, javascript and css.

But if you don’t want to go down the plugin route, and just want a simple fix to put into your functions.php file, here it is…

function callback($buffer) {
	$buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer);
	return $buffer;
function buffer_start() {
function buffer_end() {
add_action('get_header', 'buffer_start');
add_action('wp_footer', 'buffer_end');

Depending on the size of your site, how many plugins you have and your server setup, this can be a little memerory intensive and might raise your server’s load, in which case, you could use a

This kind of output buffering is more memory intensive and might raise your server’s load.

Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358