RE: How to minify html javascript and css in WordPress without plugins?
I’m facing a great problem on my WordPress website. I have used 3 plugins for minifying. But Google Speed Test says that minifying problem. Now I want to solve my minify problem without using any plugins. My website is: www.linkworld.us
Have any way?
My question is: How to minify HTML javascript and CSS in WordPress without plugins?
Yet with a few lines of code, it is possible to optimise the weight of our files without plugin. For example, to reduce the weight of HTML files from a WordPress theme, copy the following code in the functions.php file at the root of your theme:
add_action('get_header', 'gkp_html_minify_start'); function gkp_html_minify_start() { ob_start( 'gkp_html_minyfy_finish' ); } function gkp_html_minyfy_finish( $html ) { // Suppression des commentaires HTML, // sauf les commentaires conditionnels pour IE $html = preg_replace('/<!--(?!s*(?:[if [^]]+]|!|>))(?:(?!-->).)*-->/s', '', $html); // Suppression des espaces vides $html = str_replace(array("\r\n", "\r", "\n", "\t"), '', $html); while ( stristr($html, ' ')) $html = str_replace(' ', ' ', $html); return $html; }
Thanks