Easier way to change WordPress URL
WordPress stores the site URL in the database by default (which I have never understood), and it’s a pain to have to type out the UPDATE SQL or search in phpMyAdmin to change it.
But there is a simple way to put the URL into wp-config.php instead.
Simply add these two lines:
define('WP_SITEURL', 'http://www.domain.com');
define('WP_HOME', 'http://www.domain.com');
You can even fill in the hostname (and port number) automatically, which makes it super-easy to transfer between development and live sites:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
You might still need to update any URLs in the content though:
UPDATE wp_posts
SET post_content = REPLACE(post_content, "http://www.old.com", "http://www.new.com"),
guid = REPLACE(guid, "http://www.old.com", "http://www.new.com");
UPDATE wp_comments
SET comment_author_url = REPLACE(comment_author_url, "http://www.old.com", "http://www.new.com");
(Note: Don’t replace the guid field if you’re changing the URL of a live site – only if you’re making a development site live.)