Help! I Messed Up My WordPress URL Settings

If you’ve found this article, it is probably because you made a mistake when updating your WordPress url settings, and now need a solution for reversing your changes. And the problem that you have likely encountered is that the WordPress admin area is inaccessible. So you can no longer make changes via the WordPress interface.

Fortunately, if you can edit and upload files, or have direct database access, you can easily reverse the changes.

Edit and Upload functions.php

The simplest way to reverse the changes it to edit your theme’s functions.php file.

Each theme generally has a functions.php file. It will be located in your active theme’s directory at:
root -> wp-content -> themes -> [theme name] -> functions.php

Once you’ve found this file, you will need to edit it by adding the following code at the very top of the file, but within the opening <?php tag.

update_option('siteurl','http://www.example.com');
update_option(’home’,'http://www.example.com’);

If your theme does not have a functions.php file, you will need to create one. Inside of it place the following code:

<?php
update_option(’siteurl’,'http://www.example.com’);
update_option(’home’,'http://www.example.com’);
?>

Be sure to edit the code to reflect the url settings for your blog, and then upload this file to your theme’s directory. Now attempt to access your admin area. Note: You might need to reload or refresh the page a few times. When you have successfully loaded the website, edit the functions file again to REMOVE those lines that you added. Now your settings should be fixed.

Database Fix: SQL Query

If, for some reason, the above method does not work, you can accomplish the same fix by directly editing the database.

Once you have access to the database, either via phpMyAdmin or through some other database utility tool, you will need to run the following query.

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-url.com', 'http://www.new-url.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Note: You will need to update this code to reflect the url for your website. Additionally, if your website uses something other than the default database table prefix, you will need to update the wp_ prefix in wp_options to reflect the name of your options table.

And that’s all. Your settings should now be fixed.

‘WordPress Address’ vs ‘Blog Address’

The reason why it is so easy to mess up your settings is because the difference between WordPress Address and Blog Address is not well explained. The WordPress Address is the location where WordPress is installed. Or in other words, it is the directory where you will find the WordPress files. On the other hand, the Blog Address is the location where the home page of the blog will be.

In most cases, the WordPress Address is the same as the Blog Address. However sometimes, such as if you want to keep WordPress files separate from other files, you might place WordPress files in their own directory. For additional information on this topic, visit the WordPress documentation on Giving WordPress Its Own Directory.

Tags: ,

13 Responses to “Help! I Messed Up My WordPress URL Settings”

  • On December 22nd, 2008 at 9:19 am, Kim Woodbridge wrote:

    Hi - Do you think that most people who make this mistake will be able to follow those instructions? ;-) My guess is no - I know that we could (I’ve actually done it and fixed it through the database) but so many users that I encounter don’t know how to FTP much less edit the database.

  • On December 22nd, 2008 at 9:22 am, Velvet Blues wrote:

    Good point… Perhaps ‘Method 3′ should be: Hire A Professional :-)

  • On December 28th, 2008 at 4:46 pm, waseem wrote:

    thank you so much, i nearly freaked out!

  • On January 3rd, 2009 at 2:01 pm, Velvet Blues wrote:

    Haha. Yep, it happens. I’ve done this once or twice myself on different blogs.

  • On January 22nd, 2009 at 4:39 am, Rubal wrote:

    Thank you!!
    This is life saver.

  • On March 9th, 2009 at 12:12 am, Eric P wrote:

    Thanks for the tip! Very nice.

    Based on it, I created the following function (permanently add to functions.php) to enable dynamic assignments of the siteurl and home option values. This is useful to our shop as we copy the same theme to many different URLs.


    update_siteurl(); // call the function at the top of functions.php

    function update_siteurl() {
    $option_siteurl = get_option('siteurl');
    $option_home = get_option('home');
    if ( !strstr($_SERVER['HTTP_HOST'],$option_siteurl) ) {
    update_option(’siteurl’, ‘http://’.$_SERVER['HTTP_HOST']) ;
    update_option(’home’, ‘http://’.$_SERVER['HTTP_HOST']) ;
    }
    }

    You could also make this function a call from the set up menu somewhere (or based on a unique REQUEST_URI string request) to lessen the overhead of grabbing the variables on each request.

  • On March 28th, 2009 at 8:44 pm, Hyrum wrote:

    You are awesome! Thanks for the help. I was able to put everything back in order.

    Regards

  • On May 1st, 2009 at 12:38 am, Alex wrote:

    Thank you so much! I am so happy I found your site.

  • On May 20th, 2009 at 4:36 pm, Joel wrote:

    My blog is installed in a secondary domain on my webhost account. That is, there is primary account, but I can host other domains. It is in a folder of the primary account: http://www.first.com/second (where ’second’ is the folder where the site is installed and hosted.

    If I browse to the second domain using http://www.second.com, the address looks fine when I first hit the site. But when I browse to another page, I get http://www.first.com/second/page2 and so on.

    In the WP settings, the URLS are both http://www.first.com/second

    Should I change the BLOG address to http://www.second.com?

  • On June 26th, 2009 at 6:15 pm, Heather wrote:

    Thank you thank you thank you! This helped me so much! And Kim– don’t always discount people who don’t know what they’re doing. I have honestly never really messed with my database at all because I’m always too scared I’ll screw something up (I tend to do that, hence, I’m reading this post), so I didn’t even know how to get my SQL database… but I figured it out and had everything fixed in about five minutes! Yay! Thank you!

  • On August 27th, 2009 at 12:57 pm, Cyndi G wrote:

    Thanks!!

  • On September 29th, 2009 at 7:21 pm, nick rafique wrote:

    thanks very much for providing this handy tip for siteurl vairable overwrite . I have blog on my website . But my website on godady shared hosting and I need to run sitemap script . so I run sitemap script locally . this variable overwrite tip is very handy and I dont need to update my database from local to remote server . just use if condition

    thanks
    nick rafique´s last blog ..djey5f8vsz My ComLuv Profile

  • On January 22nd, 2010 at 12:15 am, Cory Mink (Yawning Yeti) wrote:

    You have no idea how much help this post was. One of the editors on my site was changing around the front page and some how ended up changing the wordpress url. After almost having a nervous breakdown I stumbled across your site, and you saved me from throwing my monitor out the window :) Thank you so much!
    Cory Mink (Yawning Yeti)´s last blog ..Mass Effet 2 Launch Trailer My ComLuv Profile

Trackbacks

Trackback URL for this entry:
http://www.velvetblues.com/web-development-blog/wordpress-url-settings/trackback/

Leave a Reply

CommentLuv Enabled

Want us to work on your project?

Contact us today for a quote. Click here to submit details regarding your project.

If you are making a general inquiry, send an email to info@velvetblues.com