How do I minify HTML without plugin? please help!

Posted in: Newspaper
Post count: 7

This them is great and I am super satisfied with it. The only problem is that I can’t find a way to minify my HTML code without having to use a plugin like auto optimise.

Post count: 7

I found some where online, that adding this code to the function.php theme file would minimise HTML for my website.

if ( !is_user_logged_in() ) {
function sanitize_output($buffer) {
$search = array(
‘/\>[^\S ]+/s’, // strip whitespaces after tags, except space
‘/[^\S ]+\</s’, // strip whitespaces before tags, except space
‘/(\s)+/s’ // shorten multiple whitespace sequences
);
$replace = array(
‘>’,
‘<‘,
‘\\1’
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start(“sanitize_output”);
}

I haven’t tried it yet because every time I try to edit my function.php file something goes wrong with my site.

Post count: 9544

Check to see if your hosting provider supports ‘mod_pagespeed’ as this can compress the HTML by removing line breaks, comments and extra spaces. Simplest way to do that, if you’re able.

Better to compress the javascript, CSS, first.

You can also manually compress the main theme template you’re using for the post template, as another option.

Post count: 7

My Javascript and Css is already minified and that was done through my hosting service but it doesn’t minify my HTML.

Chris can you tell me how to manually compress the main theme template.

Post count: 9544

Basically open up the post template you’re using, and remove double spaces, indents, etc. — remove comments, et al.

Double check as you go that it still works. Don’t delete the first few items at very top of the templates.

I use either TextEdit (Windows), or BBedit (Mac), or DreamWeaver to do this kind of thing.

Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newspaper’ is closed to new topics and replies.