Web Design and Development
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.phpOnce 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, WordPressHow to Change WordPress Directory Name or Location | Jeff King Consulting
Trackback URL:
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: www.first.com/second (where ‘second’ is the folder where the site is installed and hosted.
If I browse to the second domain using www.second.com, the address looks fine when I first hit the site. But when I browse to another page, I get www.first.com/second/page2 and so on.
In the WP settings, the URLS are both www.first.com/second
Should I change the BLOG address to 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
Brilliant! The function.php method worked for me. Thanks.
Thanks for your useful post. Finally I recovered up the blog..
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!
Thank you very much. Saved my life.
It only worked for me when I inserted:
update_option(‘siteurl’,'http://www.example.com’);
and not:
update_option(’home’,’http://www.example.com’);
I got a parse error when I tried to insert the second line.
Thank you sooooooo much. You’re a life saver!
THANK YOU!!!
Thank you. I almost had a panic attack.
I would appreciate it more if you’d include some screen shots and stating it much more clearly the topics and what really is the problem but either way its a great post I must say thanks ^^,
Thank you so much!! That really really helped me. I thought I was going to have to start all over.
I am getting the following error. What does this mean?
Fatal error: Cannot redeclare get_alloptions() (previously declared in /home/content/d/s/t/dstolfi808/html/savetheseaturtles/wp-includes/functions.php:419) in /home/content/d/s/t/dstolfi808/html/savetheseaturtles/wp-includes/deprecated.php on line 1876
Thank you very much, i restored my blog ( thanks to god and you !! ) by editing the database
this is soooo hard to follow. isn’t there an easier way?
I thought these instruction were sweet. Lifesaver. Thank you. You got to love the people with negative comments who think you owe them something. Haaa…
Thanks, I always appreciate when people let me know that I’ve been helpful. And well said!
This was so helpful! I spent hours last night trying to figure this out. Codex was completely useless! You’re not a life saver, but a 16-20 hour saver of me rewriting pages of content. Thanks so much!
That worked for me for the site in general but it didn’t work for the images within the post. Any quick fix for this?
If you changed your urls and you also want to update your image urls, then you should try our Update URLs plugin.
Holy crap… you saved my ass, sir! Thank you!
Just want to give a big thanks for this fix! I don’t know much about this type of coding, but was able to figure it out quickly and get everything fixed. Thanks again!
OMG!!!
I cant believe it..
I thought I lost everything…
You are a life saver man…
Thanks alot…
Saved my life!
Seriously just saved my ass a lot of time and trouble.
Thank you very much.
Thanks for the work-around for the changed WP URL in settings!
After replacing my current site (client’s site) with a backup from an old location my site went pear shaped and gave me a momentary anxiety attack. I used your solution coupled with your Velvet Blues Update URLs and it saved me hours of time and heart ache. Thanks for the great resource and the clear explanations!
Thanks a ton!
Dude, you saved my life. Awesome tip!
I love you.
Good Lord, THANK YOU! I completely’d screwed meself.
you saved my bacon, thanks for posting this
Hi, Thanks so much for this help! I did this and it fixed my homepage, but my other pages are still not being found…is there something else i need to do? If possible could you help me out. I would greatly appreciate it
Thank you Thank you Thank you Thank you Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I just transferred a domain to my blog, and without realizing that the change hadn’t gone through yet, I changed the wordpress url.
Saved my life. Thanks.
Thanks. Brilliant help and in response to ” Do you think that most people who make this mistake will be able to follow those instructions?” – YES! I am quite able to make a stupid mistake like that and still smart enough to follow the instructions
Since WordPress 2.2, you’re able to define the siteurl and home settings in your wp-config.pfp file.
Provided you’re running WordPress from the root of the domain, simply put the following code anywhere in your wp-config.php file, and it will automatically set the correct domain for you:
define(‘WP_SITEURL’, ‘http://’ . $_SERVER['HTTP_HOST']);
define(‘WP_HOME’, ‘http://’ . $_SERVER['HTTP_HOST']);
(Source: http://codex.wordpress.org/Editing_wp-config.php)
Thank you so much!!! You saved hours work for me.
I used option 2
Remember: if you have changed the wp_ prefix! (I did)
Thanks again
Saved my ass! Thank you!
Shit, really helpfull page. I freaked out for a moment there. But you saved my butt. Thanks!
Thank you – genius!
now that ive fixed that problem and thank you BTW. now my blog is saying a http 404 error.
It’s the second time you save my whole website ! I’m so dumb making twice the same mistake –”.. Thanks !
You are an angel!!!!!!!!
Thank you so much!
I added the code, but it still won’t allow me to view the wordpress site. Is there something special you have to do if you have Godaddy?
Thank you so much you saved me!
thnx ….
You can create WordPress URL Settings so
http://i46.tinypic.com/19um2d.jpg
1…http://……../phpMyAdmin/
2…Databases…/blog WordPress
3…localhost »blog »wp_options
4…option_id 1 ..
5…team edit
6…write a new URL http://meineseiten.com/blog/
7…Go
You are a lifesaver!!!!
YOU SAVED MY LIFE!!!!!! THANK YOU SO MUCH!!!!!!!!!
Thank you so much for this. I nearly had a heart attack when I accidentally changed one of the URL’s. My issue is getting Flickr to connect to a self hosted wordpress blog. Still trying to figure that one out, but I sure won’t make the same mistake again! Thanks a million.