Remove Wordpress comments in source code

Remove notes in the source code

When writing a WordPress theme, comments are often added to the source code, which makes sense, because they provide a better overview. But also plugins like to automatically create some comments, hints or annoying brandings in the source code of a website, which are of course not really helpful and do not offer any real added value. But such comments in the source code of WordPress can be easily removed, for example with a small snippet. As soon as this is inserted, hints like the link to wpSEO and other plugins are removed. So there is again a little more overview, less advertising, but above all simply no superfluous lines in the source code.

Copy the following into the functions.php of your theme:

function callback($buffer) {
	$buffer = preg_replace('//', '', $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');

Matter of taste

Some people simply hate the comments and want to remove them, others just don't understand why a paid plugin also leaves advertising in the source code. No matter which group you belong to, with the snippet above, almost all comments in the source code of your website are history. The performance won't increase noticeably, but it's a question of your own attitude. If the comments bother you at work, or you just don't want them, the snippet is the right thing to do.

About Christian

My name is Christian and I am co-founder of the platform fastWP. Here in the magazine I am responsible for the more "technical" topics but I like to write about SEO, which has been my passion for over 10 years now.

1 thought on “Kommentare im Quelltext entfernen”

Leave a Comment

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

en_GB