How To Change Your Site URL

A problem I see come up in the WordPress forums quite often is a blogger who is locked out of his own blog. This is usually a result of playing with the values found at Settings > General. See screenshot below. (click to enlarge)

g-settings

Although there are legitimate cases of wanting to change the Blog address (URL), such as when you are planning to give WordPress its own directory, for the vast majority of users however the values depicted in the image above should be left alone. It's when people start changing them that chaos ensues. Fortunately the fix is an easy one. In this post I'll give you three different methods for changing the values back to what they should be should you find yourself locked out of your blog.

Method #1: Edit wp-config.php
This is probably the easiest method of the three. Open the wp-config.php file in a plain text editor such as Notepad and add the following lines ...

define('WP_HOME','http://yoursite.com');
define('WP_SITEURL','http://yoursite.com');

... where yoursite.com is the correct URL. It goes without saying you will need to log in to your site via FTP.

Method #2: Edit the active theme's functions.php file
This method is a bit more involved than the previous one but is still fairly straightforward. We will need to edit the functions.php file of the currently active theme. If it doesn't exist then we'll need to create it. It's important to note it must belong to the currently active theme.

Okay, open functions.php in a plain text editor and immediately after the line containing the opening <?php tag add the following ...

update_option('siteurl','http://yoursite.com');
update_option('home','http://yoursite.com');

... where once again yoursite.com is the correct URL.

If the active theme doesn't have its own functions.php file don't worry it's easy to create. In a plain text editor create a file called functions.php and add the following to it ...

<?php
update_option('siteurl','http://yoursite.com');
update_option('home','http://yoursite.com');

Upload the file to the active theme directory.

Method #3: Edit the database
Although this method can seem very daunting, even downright terrifying to newbies, it's not that difficult. One thing to remember - you will be directly interacting with your database. There is no undo. If you make a mistake the consequences could be disastrous. Prior to manipulating your database, and I can't stress this enough, create a backup. You will find easy step by step instructions at the Codex. Scroll down to the section called Backup Documentation.

Now that I've scared the jeebus out of you let's proceed. For this example we will be using phpMyAdmin - a program for manipulating the MySQL database.

Log in to your host's phpMyAdmin and select the appropriate database. See screenshot below. (click to enlarge)

choose_database

Obviously your environment will most likely look different. I have a bunch of local WordPress installs hence the reason for all of those databases.

Once you have selected your database you will come to a screen like the one below. (click to enlarge)

tables

Keeping the image above in mind you need to click the Browse button of the wp_options table. Now, your table prefix may or may not be wp_ depending on if you manually changed them to something else. For the purposes of this article we'll assume not.

After clicking the browse button of the wp_options table you will see the screen below. (click to enlarge)

siteurl

Upon clicking the pencil icon you will see the screen below. (click to enlarge)

edit_siteurl

Once you changed the siteurl value back to what it should be all you need to do is go back to the wp_options table, look for home and do the same thing.

About the author
Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him writing the occasional article and toiling away in the forums at WeblogToolsCollection.com. He also hangs out at the WordPress support forums lending a hand where he can. You can also find him at his other blog LenKutchma.com

2 Responses to “How To Change Your Site URL”

  1. [...] This post was Twitted by wpcanada [...]

Leave a Reply

CommentLuv Enabled