Speeding up WordPress
Wednesday, January 6, 2010
Many people have migrated to blog platforms like WordPress rather than a static web site – and for good reason. There are many reasons to use WordPress as a CMS. However, speed is almost always an issue for any web site with content other than some text. And this is where much of WordPress’ bloat really can slow down your web site!
I have been scouring for some time attempting to find a silver bullet for WordPress speed problems, and there are tons of articles, sites, etc detailing mostly outdated or incorrect information.
So I’m going to be putting as much as I can here, real, TESTED information. I highly recommend using Firebug addon for Firefox to test your blog so you can see how things run.
Tips – many will vary depending on your host configuration and your Theme. We’ll also assume a host (like godaddy) which does NOT compress js and css files but can be configured to compress text. (more on that later, for now let’s assume you have it working properly)
make the following changes in wp-config.php
/* I like this as a security - someone tries to open /wp-config.php and get redirected. there are other ways to do it... but here's one */
if (eregi("wp-config.php", $_SERVER['SCRIPT_NAME'])) {
Header("Location: index.php"); die();
}
// below just because I like putting this hard coded rather than using unnecessary database calls for the info.
define('WP_HOME','http://yourdomain.com');
define('WP_SITEURL','http://yourdomain.com');
/* I don’t like sending the long cookie names wordpress defaults too. A few bytes savings per file requested.*/
define(‘USER_COOKIE’, ‘ua’);
define(‘PASS_COOKIE’, ‘pa’);
define(‘AUTH_COOKIE’, ‘au’);
define(‘SECURE_AUTH_COOKIE’, ‘sec_’ . COOKIEHASH);
define(‘LOGGED_IN_COOKIE’, ‘li’);
define(‘TEST_COOKIE’, ‘wtc’);
// Enable the WordPress Object Cache:
define(‘ENABLE_CACHE’, true);
——————
That ends the changes in wp-config.php.
Now, things that are theme oriented!
In your functions.php file, I don’t like all the darn filtering that WP does by default, and all the JUNK it puts in the headers. Annoying, useless, slows down your site, etc. Obviously if you’re using some of that functionality you’ll need to leave things in… but try:
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Removes the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Removes links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link'); // Removes the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link'); // Removes the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link'); // Removes the index link
remove_action( 'wp_head', 'adjacent_posts_rel_link'); // Removes the relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator'); // Removes the WordPress version i.e. - WordPress 2.8.4
remove_action( 'wp_head','rel_canonical');
Now onto the header.php file. Your theme may vary, but the largest speed increases will come from reducing unnecessary calls to the database and long-winded-bloated functions. Chances are, none of these settings will EVER change on your site, if they do it’s easy to modify!
First off, remove unneeded javascript junk – javascript is cumbersome and slow. Needed for some functions but hardly for most.
Notice my css file name is changed to add a .php — that will be explained later, but put your own settings in.
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
with:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
replace:
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style_a.css" media="all" />
with:
<link rel="stylesheet" type="text/css" href="/wp-content/themes/thunderpaw-web-marketing/style_a.css.php" media="all" />
Onto the stylesheet. If your host, like mine, doesn’t gzip css files – change them to a .php and make the following changes:
change stylesheet:
add to beginning:
<?php
header("Content-Type: text/css");
echo '
....(your css goes here)...
';?>
This will enable gzip compression of your style sheet and your html.
Lots more to come.
-David Lyle


Comments
No Comments
Leave a reply