Installing WP-Cache on WordPress

Without a doubt, Ricardo Galli’s WP-Cache is my favorite WordPress plugin. It speeds up WordPress significantly, therefore making your blog more appealing to your site vistitors.

Installing WP-Cache

You can either install WP-Cache like most plugins, by dropping it in your plugins folder: wp-content/plugins/. Or you can manually install which means you have to create a symbolic link from wp-content/advanced-cache.php to wp-content/plugins/wp-cache/wp-cache-phase1.php, something which is impossible to do if you do not have shell access to your hosting account. This is why I recommend the normal plugin install. However you still might have a problem with file permissions, which WordPress will warn you about once you go to Admin – Options – WP-Cache. Usually it will be due to something not being writeable, like:

  • wp-content/cachedirectory
  • wp-content/
  • wp-config.php

You will need to change all three to permissions 0777. This still might result in an error with the symbolic link not creating. For this you must an FTP client like SmartFTP that allows you to change the stickybit. Depending on the ftp client you are using, this might show up as Stickybit or simply you will have a row of 4 boxes to type in a number. You will want to change the directories above to 7777, so that the symbolic link will create. This is usually the problem and solution, if you do not have shell access.

You can read a short description of Unix permissions on WebmasterWorld (membership required).

Once you get pass the permission issues, you should be able to view WP-Cache Options and configure the caching expire limit and exclude pages from caching. If you ever decide to remove WP-Cache and your site no longer works, you must manually go into wp-config and remove the define(“WP_CACHE”, true): line. For security reasons you should change the permissions of wp_config back to 644. Just remember to change the permissions on this file if you plan to enable or disable Wp-Cache.

WordPress 2.0 & Shortstat Plugin

For WordPress 1.5, I had done some changes to Jeff Minard’s Shortstat plugin and since I recently installed WordPress 2.0 on my personal site, and since Shortstat 1.3 still works for WordPress 2.0, I figured I would go ahead and redo the color scheme and make it fit in more with WordPress 2.0’s new backend colors.

For more detail on the original changes see my original posting of a Custom Shortstat Plugin.

WordPress ShortStat Plugin in Blue

If you like the blue scheme you can download the plugin with the complete changes here:

wpshortstat.blue2.txt

Or if you like the color scheme and want to disable the IP lookup feature as well, download the complete changes here:

wpshortstat.blue.nolookup.txt

You can copy and paste the code into the Plugin Editor or rename the file to wp-shortstat.php and upload it to your server.

Since WP-Shortstat stopped working on WordPress 2.0.1, these custom versions are now based on HappyArt Blog’s modified wp-shortstat. My CSS changes were added by HappyArt Blog to his version, so wpshortstat.blue2 is the same as his plugin. For the lastest version go HappyArt Blog.

Use PHP To Display Elements

Here is something which I wanted to do with WordPress for a while now. In the sidebar, I wanted to remove the ecommerce seals for the SSL certificate and PayPal from the main blog entries and only have them display for the WordPress Pages. This is where The WordPress Codex comes in handy and explains how WordPress Conditional Tags can be used to display content based on what page the reader is currently viewing. There is even a code sample for the sidebar.

In my case, though it was really simple, I just added the html code for the gifs into a php section, similar to this:

<?php if (is_page()) {
    echo "<img src="http://www.site.com/logos/paypal.gif" />";
    }
?>

However note, that this code will not work! If you notice, that the echo statement uses double-quotation marks and that the html code does as well, you will realize that in order for this code to work, you have to escape the quotation marks in the html by using the backslash.

Therefore the correct code would look like this.

<?php if (is_page()) {
    echo "<img src=\"http://www.site.com/logos/paypal.gif\" />";
    }
?>

The is_page tag is used in this case to mean that if I am on a WordPress Page, then include the html in the echo command. To add more html code, I would just add another echo command, making sure I enclosed it in quotes, and that I escaped any quotes in the html with a backslash, and finally in PHP, you have to end each command with a semicolon.

For further information on conditional tags see the WordPress Codex.

Custom Shortstat Plugin

A very handy plugin that I use for web stats is Jeff Minard’s WordPress port of Shortstat, which is a script that Shaun Inman originally wrote.

Shortstat Plugin Conflict

It appears that Jeff recently updated the Shortstat plugin to version 1.3 and that there was a conflict with another great plugin, Google Sitemap Generator. After some research on WebKeyDesign, I found that the 2.7 version of Google Sitemap Generator conflicts with the 1.3 version of the Shortstat plugin. But the 2.7.1 version works fine. If you have not updated Sitemap to 2.7.1, first do that then download the new 1.3 version of Shortstat and set that up. This should make both plugins work.

Shortstat Slows Down WordPress Dashboard

As if the Dashboard was not slow enough some days, Shortstat adds even more delay due to the IP address lookup that it does. You can disable this feature if you do not particularly care about what country your visitors are from. Most webmasters want to know what state or region in the USA, instead of the country, so for many webmasters this feature is not specific enough. To disable the feature just go to line 119 and look for the following code:

$coinfo = @file('http://www.hostip.info/api/get.html?ip=' . $ip);
$country_string = explode(':',$coinfo[0]);
$country = trim($country_string[1]);

Change the code to this:

// $coinfo = @file('http://www.hostip.info/api/get.html?ip=' . $ip);
// $country_string = explode(':',$coinfo[0]);
// $country = trim($country_string[1]);
$country = '(Private Address) (XX)';

The Dashboard will still be slow due to feeds but Shortstat will not add to the delay.

Shortstat Database Data

If you take a quick look at the stats that you get, you can tell that they can start to add up and that while these stats are adequate for a quick daily glance, they are not really something to keep for a year or even more than a few months, so what you eventually need to do is zap the stats from time to time.

Shortstat adds two tables to the WordPress database: ss_stats and ss_search. I personally zap ss_stats more often than ss_search, since ss_search has the data for sites that refer to me and what searches people have used on my weblog. You can however zap both tables. If you have your log hosted on cPanel or have access to just phpMyAdmin you can easily do this. You will need to select only the two tables, and none of the other tables or you could end up deleting your blog data!!! Make sure you backup first. You can reference my Optimize Your MySQL Databases instructions, which should help you understand the process a bit better. The only difference is that instead of optimizing the table, you will be choosing to empty the selected table.

Shortstat in Blue

One last thing that I like to do with Shortstat is change the color design. For some reason the red links really bother me, but since I started changing it I ended up adding color to the columns too. Here is kind of what it looks like in blue:

Shortstat Plugin in Blue

Custom 1.3 Shortstat Plugin

If you like the blue scheme and want to disable the IP lookup feature, you can download the plugin with the complete changes here:

wpshortstat.blue.txt

You can copy and paste the code into the Plugin Editor or rename the file to wp-shortstat.php and upload it to your server.

Custom Shortstat Plugin for WordPress 2.0

Since WordPress 2.0 came out I redid the changes, see WordPress 2.0 Shortstat Plugin.

Speeding Up WordPress

Now this may seem rather obvious, but many WordPress users enable an option that slows down postings even when the option actually warns you that this slows down postings. If WordPress just seems slow to you when you are adding content, make sure that under Options – Discussion Options – Attempt to notify any Weblogs linked to from the article is cleared and not checked. This will stop WordPress from pinging multiple websites and slowing down the posting process.

For speeding up WordPress for viewing, you need to install WP-Cache 2, which is an excellent plugin and in my opinion one of the top essential WordPress plugins.

Once your WordPress databases grow, you should definitely take the time to optimize your MySQL databses. The process is quite simple and the benefit is immediate.

Redirect Your index.rdf

I was looking through AWStats and seeing quite a few requests for https://www.webkeydesign.com/index.rdf which is resulting in 404 Page Not Found errors as I do not have this file and WordPress does not create the RSS feeds at this location. The solution is of course to either create the index.rdf file or simply redirect it.

In cPanel you simply use the Redirects panel to have any url for your site redirect to another page. In this case the redirect ends up going to www.webkeydesign.com/feed/, which is where I actually have RSS feeds for the site.

There is some debate as to why index.rdf is being searched in the first place, but the concensus is that GoogleBot may be defaulting to this location for various sites simply looking for RSS feeds.