Tell your Project me

How Minificar the HTML in WordPress without Plugins

We follow with some trick to improve the speed of load of our Web in WordPress, and is that Google values much the time of load of the webpages in its last revision of the algorithm search. Yacht we spoke of how to increase the speed using a CDN in WordPress, today we will teach to you to compress the HTML of your WordPress subject.

Several exist plugins to realise this function, but a thing we know clearly is that whatever less plugins we have installed greater will be the yield of our WordPress. For that reason we will teach a trick to you to compress the HTML of your subject of WordPress without using plugins.

The function is the one that we left you next, you must integrate it in your Child Theme or in plugin of functions if you have it implemented, both options are correct. Also functions.php of your subject but it is not recommendable since will work in the file if you update it you will lose the modification.

//Funci ³n for Minificar the HTML class WP_HTML_Compression \ {protected $compress_css = true; protected $compress_js = true; protected $info_comment = true; protected $remove_comments = true; protected $html; public function __construct ($html) \ {if (! empty ($html)) \ {$this->parseHTML ($html); }} public function __toString () \ {return $this->html; } protected function bottomComment ($raw, $compressed) \ {$raw = strlen ($raw); $compressed = strlen ($compressed); $savings = ($raw-$compressed)/$raw * 100; $savings = round ($savings, 2); return ''; } protected function minifyHTML ($html) \ {$pattern = ˜/< (?|< (? |<! (? --). *? -->|< (? [/w.: -] *) (: . *? œ|'. *? ˜|[^™ œ>] +) *>|(? ((< [^! /w.: -])? [^<] *) +)|/si'; preg_match_all ($pattern, $html, $matches, PREG_SET_ORDER); $overriding = false; $raw_tag = false; $html = ''; foreach ($matches ace $token) \ {$tag = (isset (] $token [˜tag™))  to strtolower (] $token [˜tag™): null; $content =] $token [0; if (is_null ($tag)) \ {if (! empty (] $token [˜script™)) \ {$strip = $this->compress_js; } else if (! empty (] $token [˜style™)) \ {$strip = $this->compress_css; } else if ($content == '') \ {$overriding =! $overriding; it continues; } else if ($this->remove_comments) \ {if (! $overriding && $raw_tag! = ˜textarea™) \ {$content = preg_replace (˜/).) *-->/s™, '', $content); }}} else \ {if ($tag == ˜pre™ || $tag == ˜textarea™) \ {$raw_tag = $tag; } else if ($tag == ˜/pre™ || $tag == ˜/textarea™) \ {$raw_tag = false; } else \ {if ($raw_tag || $overriding) \ {$strip = false; } else \ {$strip = true; $content = preg_replace (˜/(s+) (w++ (? <! baction|balt|bcontent|bsrc) = "")/™, ˜$1™, $content); $content = str_replace (˜/>™, ˜/>™, $content); }}} if ($strip) \ {$content = $this->removeWhiteSpace ($content); } $html. = $content; } return $html; } public function parseHTML ($html) \ {$this->html = $this->minifyHTML ($html); if ($this->info_comment) \ {$this->html. = œn. $this->bottomComment ($html, $this->html); }} protected function removeWhiteSpace ($str) \ {$str = str_replace (œt, ˜˜, $str); $str = str_replace (œn, '', $str); $str = str_replace (œr, '', $str); while (stristr ($str,™™)) \ {$str = str_replace (˜˜,™™, $str); } return $str; }} function wp_html_compression_finish ($html) \ {return new WP_HTML_Compression ($html); } function wp_html_compression_start () \ {ob_start (˜wp_html_compression_finish™); } add_action (˜to get_header™, ˜wp_html_compression_start™);

With this trick you will be able to compress the HTML of your subject of WordPress; but you need a greater compression as for example CSS and the JS, most recommendable is some of plugins of breaks.

It accelerates your Web and in order to position in Google

In our gratuitous course you will among others learn things to optimize the speed of load of your WordPress to improve the SEO.