Speed up WordPress

Posted on 13th July, 2013 Leave a Comment

This is something that I add to all my sites, it will increase the load time. Check your site now on http://gtmetrix.com/. < This site gives you a breakdown of your sites performance and will show you the areas that you need to improve on. This page is dedicated to improving your sites performance, which in turn keeps readers happy. This is why this snippet is part of my must have snips. It increased my sites performance by about 6%.

Add this above everything in the header.php of your theme, add it right at the very top of your document. What this does is a little bit of magic, it determines what type of content encoding the browser will accept (“gzip”, “deflate” or none at all) and will return its output accordingly.

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

After you check again with gtmetrix.
You’re aiming for all green bars really, anything that is red should be sorted out pretty quickly. Hopefully now you should see a change in your performance.

There are still some other things you can do to help with the performance…


Setting the header expires on files and images in your .htaccess file.

You’ll need to access your web host to do this, but that really is simple.
Basically you have two choices; You can do this with an FTP client or through your websites cPanel, you would have been given your login details for the cpanel and ftp when you registered with your web host, so check your emails for those.

To access the cpanel add /cpanel to your domain name. ex:http://mydomain.com/cpanel

Onto the htaccess…

Once you have your .htaccess file, create a backup. ‘Copy & paste’ the file to your desktop and rename it as .htaccess-backup, We’re doing this just in case you make a mistake, you’ll just be able to remove the -backup from the name and re-add the .htaccess file back to your server.

Open up your .htaccess file, and add this below any other content that’s in this document.

### Set Expires Headers ###

# Enable Expirations
ExpiresActive On

# Default Directive
ExpiresDefault "access plus 1 month"

# Favicon
ExpiresByType image/x-icon "access plus 1 year”

# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"

ExpiresByType text/css "access 1 month”

# JavaScript
ExpiresByType application/javascript "access plus 1 year"

For more on the htaccess file and WordPress security click here

Leave a Comment

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]