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.
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.
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: http://test.mysite.com | Live site: http://mysite.com
Dev site: http://mysite.com/wp | Live site: http://mysite.com/blog
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.
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!