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?

Mohi Uddin Brong Asked on July 20, 2017 in Website & Blog.
Add Comment
2 Answers

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

Brong Answered on July 21, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.