If you transferred your Wordpress site to a new domain or changed your current Wordpress URL, you'll probably find a bunch of references to the old site URL that need to be updated. Wordpress stores the site URL, links in images, and links in posts and pages as full URLs. When you change your URL, Wordpress does not automatically update old links. This post tells you how to update all of these links without having to manually edit each and every post.
This post doesn't explain how to transfer a Wordpress site. You can read some more details about moving Wordpress here. Typically when completing a test site and moving to a production server, I'll do a full MySQL dump using
mysqldump --add-droptable
via command-line, then transfer all files and process the SQL on the new server.Copying your WP installation to a new server does not replace URL references automatically, so after any transfer you end up with a bunch of broken links. Not good! Fortunately there are a few easy SQL commands you can run to update your posts, pages and site URL.
Replace the references to olddomain.com and newdomain.com in the SQL code below with your actual URLs. Then you can run each query via phpMyAdmin or command-line, whatever your preference.
Always make a backup before doing bulk changes to your Wordpress database!
Step One: Replace URL in config
1
2
3
| UPDATE wp_options WHERE option_name = 'home' OR option_name = 'siteurl' ; |
Step Two: Replace URL guid in WP posts
1
2
| UPDATE wp_posts |
Step Three: Replace links in WP post content
1
2
| UPDATE wp_posts |
Now you can just browse to your new site and test everything out. If everything went well, the SQL commands should have fixed all references to the old links in your Wordpress posts and site config.
0 comments:
Post a Comment