Remove HTML Comments at Web Source on WordPress Site

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 memory intensive and might raise your server’s load.


source: cazue

Artikel terkait:   Apache/.htaccess: Specify a Vary: Accept-Encoding header

Isi Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

÷ one = seven

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top