Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function minify_html(){
- ob_start('html_compress');
- }
- function html_compress($buffer){
- $search = array(
- '/n/', // replace end of line by a space
- '/>[^S ]+/s', // strip whitespaces after tags, except space
- '/[^S ]+</s', // strip whitespaces before tags, except space
- '/(s)+/s', // shorten multiple whitespace sequences,
- '~<!--//(.*?)-->~s' //html comments
- );
- $replace = array(
- ' ',
- '>',
- '<',
- '\1',
- ''
- );
- $buffer = preg_replace($search, $replace, $buffer);
- return $buffer;
- }
- add_action('wp_loaded','minify_html');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement