Enable Gzip Compression: 6 Easy Ways For WordPress [2019]

Published by Taran007 on

6 ways to Enable gzip compression in WordPress

Enable Gzip Compression: Best things you must do to make your website Performance faster to is to enable WordPress Gzip compression. It is a crucial aspect because simply put, if you want your website. performance to be faster, the size of the pages you need to serve to your visitors needs to be Reduced.



Enable Gzip Compression

Summary

The server supports .htaccess files (applicable to Apache and Litespeed servers). Make a .htaccess file in WordPress “root directory”. There are two kinds of code in the .htaccess file to enable gzip compression.

This is How the warning looks like on GTMetrix:

GTmatrix Gzip Compression

This is a high recommendation on Google PageSpeed Insights:

Pagespeed Gzip Compression

How to Check for GZip compression Status.

Before you Make any changes, you should want to check whether your website’s gzip Compression is already enabled for your WordPress site. There are quite a few other sites to Check Gzip Compression. These are the Links.

NOTE: Make sure to backup of The File in Which You Are Going to Make Changes. Because any Tiny errors in those files can break your site and make it go Offline instantly. Create a copy of your current working version before Doing any changes so that you can Revert Changes to it if something goes wrong.


1. Using Index.php File.

Open the index.php file in the root directory of the website (note that it is not the root of the theme), find:

Define(‘WP_USE_THEMES’, true);

Add the following code below:

Ob_start(‘ob_gzhandler’);

The server must support Zlib Compression Functions before it can be started. You can discard a web probe and query it on the server to see it.

This method is the simplest one, but there is a small drawback, that is, each time the program is upgraded, the file must be re-edited.Also Check: 7 Tips for SEO Image Optimization [Complete Guide] 2019


2. Using.htaccess File.

The second method requires the server to support .htaccess files (applicable to Apache and Litespeed servers). Create a .htaccess file in the WordPress root directory. There are two kinds of code in the .htaccess file to enable gzip compression. The code is as follows:

The first:

Php_value output_handler ob_gzhandler

Second:

<IfModule mod_expires.c>

ExpiresActive On

ExpiresByType image/gif A2592000

ExpiresByType image/jpeg A2592000

ExpiresByType image/png A2592000

ExpiresByType image/x-icon A2592000

ExpiresByType application/x-javascript A604800

ExpiresByType text/css A604800

</IfModule>

<IfModule mod_deflate.c>

SetOutputFilter DEFLATE

AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript

</IfModule>

Also Check: WordPress SEO optimization: 10 Tips to Improve SEO Easily [2019]


3. Enable GZIP via php.ini File.

Enable GZIP through php.ini (Gzip method is enabled under Win server), provided that the server supports php.ini redefinition, you can add the following code in php.ini:

Zlib.output_compression_level = number (the number is a value of 1-9, 1 has the lowest compression ratio, it is recommended to take 5)

It should be noted that if the gzip function is disabled in the .htaccess file, then gzip should be enabled in the .htaccess file after opening it in the php.ini file, otherwise it will have no effect.Also Check: Increase Blog Page Views to 50% in the Normative way [Free]


4. Enable Gzip Using Plugin.

There are Alot of Plugin to Choose From to Enable Gzip Compression in WordPress. Below are The List of Few. Just Install the WordPress GZIP plugin And Enable Gzip Compression with One Click.

Plugin Name: WP Performance Score Booster.

Plugin Name: Pagespeed Ninja

Plugin Name: Enable Gzip Compression

Also Check: 8 Coolest WordPress Tips & Tricks You Should Learn Today 2019


5. Enable Gzip Comparison Using Function.php

Find the function.php file below the theme and add the following code to this file:

//Gzip compression

Function dtheme_gzip() {

If ( strstr($_SERVER[‘REQUEST_URI’], ‘/js/tinymce’) )

Return false;

If ( ( ini_get(‘zlib.output_compression’) == ‘On’ ||ini_get(‘zlib.output_compression_level’) > 0 ) || ini_get(‘output_handler’) == ‘ob_gzhandler’ )

Return false;

If (extension_loaded(‘zlib’) && !ob_start(‘ob_gzhandler’))

Ob_start();

}

Add_action(‘init’,’dtheme_gzip’);

//End of code


6. Enabling GZIP Page Compression via CPanel

Rather Than enabling GZip compression at WordPress level, you can do Gzip at the server level. This Method Will Make all of your websites hosted on your server would now be fully gzip enabled. 

Enable Gzip Compression in Cpanel

Follow These exact steps for this procedure:

  1. Log in to the CPanel.
  2. Click on the “Optimize” Option.
  3. Choose the “Compress All Content” option.
  4. Press on Update settings.
  5. Test for Gzip compression, and you’re Website is Gzip Enabled.

Also Check: Top 10 Most Popular WordPress Themes 2019 [SEO OPTIMIZED]


How to Disable Gzip Compression.

To Disable Gzip feature is much Easier. You Just Have to reverse the above changes. You Have to remove all of the additional codes which we added to the config files. Also, disable the plugin, or disable the “Optimize website” feature is the CPanel.

Afterthat rerun the tests to check whether the Gzip compressing of files has been disabled.


Conclusion

You can easily achieve Huge saving by enabling WordPress gzip compression, It Can Improve Website Speed. Also, By Enabling Gzip Compression you Can Save up to 82% on the size of files. This is a Best way to make your website much faster.

The above five methods can open the GZIP compression function of WordPress, but only one way can be used to open it, otherwise, there may be conflicts. It is recommended that everyone use the fifth or Fourth one, which is more convenient.

After setting it up, you can test the compression effect at Above Mentioned Website’s. Links in the Beginning of This Article.

Also Check: CHEAP WEB HOSTING IN INDIA [FREE DOMAIN+SSL] HOSTKARLE