When it comes to compressing HTML documents in WordPress, you can make things better by adding extra code to your .htaccess file. If you don’t like the method, you can leave the same job to always trustworthy PHP. We all know the power of PHP, so handling Output Compression shouldn’t be a difficult task for it. And it isn’t.
A single line of code in index.php file will do the trick:
- Locate the root directory of your WordPress installation
- Navigate to index.php and open the file
- Copy and Paste the following code on top of the document:
But, allowing this piece of code to do its magic takes one more step. And that is enabling it in php.ini file. Don’t worry; it’s not a big deal:
Set zlib.output_compression = On
You can change level of compression by altering number in the following function:
zlib.output_compression_level = d
“d” can be any number from 1-9 where 1 represents lowest level of compression and 9 the highest one.