Moving WordPress

Lately I’ve helped move several wordpress sites from a development area to a live site. The development area can be on a different domain, sub-domain or just set up in a different directory. The move can go easy or smooth… depending on how the developers built links to pages and images within the site.

I’m going to go back to basics here for a minute to try to make this easy for anyone to understand. When you make a link you can build the path in a relative or absolute fashion.

Relative Links

Links that are relative to the file which calls it. An example of a relative link would be:


The / at the front tells the browser to look in the root web directory for the file index.php. You could also make a link like this:


The lack of the leading slash means that the browser will look in the directory where the link is called.

Absolute Links

An absolute link starts with a protocol like http://

How does this help?

If you use relative links in your content, and your wordpress installation is in the same place relative to the web root in your live and test copies then all of your links will still work after the move. Some example of this would be:

Dev site: | Live site:
Dev site: | Live site:

WordPress Template Tags

WordPress gives developers some handy tools for coding URLS to make the site easier to move. These work in the php templates for wordpress.

Site URL

The template tage site_url() returns (drum roll) the site url.
I can write my links like this (only in the PHP templates):

<?php echo site_url(); ?>

And here is what the browser sees:

If I need to get to an image in the uploads directory it would look something like this:

<?php echo site_url(); ?>/wp-content/uploads/myimage

Notice how I put the rest of the link outside of the open and close php tags.

That’s just an example. WordPress actually has template tags to access all the places that commonly need accessing. Here are just a few examples.


Check out the wordpress documentation for more. See the related tags at the bottom of the page.


Sometimes you just have to update different links after you move a site. If so, you can try a plugin which will update all of the links in the content (not templates) for you. I’ve had a good experience with Velvet Blues Update URLs

Just make sure you match the old and new URLs carefully. If you put a slash on the end of the old URL it should also be on the end of the new URL.

Good luck with your move!

WHM/Cpanel Tips

I recently switched from Debian Squeeze/Cherokee webserver back to a more typical VPS setup with CentOS/WHM/Cpanel. Cpanel does make it easy to manage many sites… but it can make other common tasks a bit more difficult. For example, I could not get git to install until I found out that cpanel disables perl upgrades. (Thanks Nick!

Nick’s suggested command worked like a charm.

yum --disableexcludes=main install git

My next problem was that I don’t want to use the default document root for all of my sites. In cherokee you can easily set the document root for each vhost through their admin interface. Not so, with cpanel. After a bit of searching I found that you can edit individual vhosts here:


After editing run:

/scripts/ensure_vhost_includes --user=$username

WP E-Commerce Basics

WP E-commerce is a powerful plugin, but getting started can be a bit messy. Here are some tips.

Go to the checkout page when you click “Add To Cart”

The add-to-cart button uses a javascript to stay on the same page while submitting the product form. To make it go to the checkout page we want to remove the javascript. This can be done by changing the name of the containing element. The javascript effects form.product_form. If you look at the product template you can change the class here:

The other thing you need to change is the action. The default form action is the same page on which the form exists. Change that to the checkout page.

Fix the checkout form

The checkout form can start off pretty messy looking, depending on your containing theme. What I like to do when styling plugins is create a separate stylesheet for the plugin, then call it at the bottom of header.php. That way the styles will override the plugin styles.

The checkout form template is wpsc-shopping_cart_page.php

To edit it copy this to your theme directory. WPEC has a tool that does this for you in Settings — Presentation. Don’t forget to flush the theme cache.

Two carts are displaying on checkout page

Change the shopping cart settings to widget instead of page in presentation.

Checkout page is broken

If there are no address fields showing on the check out page make sure that if “enable shipping” is selected you have valid shipping methods.

Checkout page has break tags in the form fields

Remove line breaks from the label tag. Thanks shivaweb.

Django – restart fcgi

This post is mostly for me… to help remember some things about working with django. Because django is loaded into memory on start-up you need to restart the process when changes are made to the code. I am currently using django with fcgi on a cherokee server.

In the terminal to your server type:

ps -ef | grep python

Look for the process ID which is running django. Then type:

kill -HUP [processid]

Now that you have killed the process you need to restart it. I usually just copy/paste the python command that is listed when I grep the processes. It looks something like this:

python /path/to/django/ runfcgi protocol=scgi host= port=35782

You can also set this up to be automated, but I have not done that yet.