Enable Gzip compression in WordPress (and not only)

Checking my blog performance I noticed that after the theme upgrade gzip compression is no longer active.

I will give you a easy tutorial in order to enable gzip compression without the installation of any plugins (like cache, super cache and so on) that I really hate.

First of all you need to check your php system gzip compression support.

Create a phpinfo.php file and upload to your site host (remember to delete it after the check)

&lt;?php<br />
phpinfo();<br />

From your browser launch the new phpinfo.php file http://www.yourblogurl.com/phpinfo.php and check php environment configuration


If the gzip encoding is not enabled on your HTTP server check with your system admin how to enable it (on Apache HTTP Server refers to mod_deflate).

Open your index.php and add the following lines on the top

&lt;?php<br />
if(isset($_SERVER['HTTP_ACCEPT_ENCODING']) &amp;&amp; substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))<br />
ob_start('ob_gzhandler');<br />
else<br />
ob_start();<br />

Save and upload the new index.php and it’s done.

Now check your site compression for example using this tool http://www.whatsmyip.org/http_compression/, you will see something like this


2 Replies to “Enable Gzip compression in WordPress (and not only)”

  1. thank you so much, I’ve tried and used different gzip plugins and it caused my blog to not work or open even, and the feed wasn’t updating.

    I did what you said and it worked just fine. thank you so much, and have the best day. 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.