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.
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.
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.
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: blogs, WordPressTrackback URL for this entry:
http://www.velvetblues.com/web-development-blog/wordpress-url-settings/trackback/
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
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.
Good point… Perhaps ‘Method 3′ should be: Hire A Professional
thank you so much, i nearly freaked out!
Haha. Yep, it happens. I’ve done this once or twice myself on different blogs.
Thank you!!
This is life saver.
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.
You are awesome! Thanks for the help. I was able to put everything back in order.
Regards
Thank you so much! I am so happy I found your site.
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?
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!
Thanks!!
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
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