Oh no! You’ve accidentally changed your WordPress site URL in the admin settings! What are you going to do?
STEP ONE: Copy the code below and create a file called sitereset.php.
STEP TWO: Upload the file via FTP to your WordPress root folder.
STEP THREE: Open up your web browser and access the file. (http://www.yoursite.com/sitereset.php)
STEP FOUR: Enter the correct site url information into the text box.
STEP FIVE: Once the site url has been changed to the correct URL, DELETE sitereset.php completely from the server.
The following code is written in PHP 5 and utilizes the mysqli php extension.
Please use this file at your own risk!
<?php
#### WORDPRESS RESET ###########
## ##
## Allan Collins ##
## http://allancollins.net ##
## ##
## 1-12-2009 ##
################################
// HOW TO USE:
// Simply type in the url in the text box to reset the WordPress site url.
// WARNING:
// This file can be a HUGE security risk and has the potential to seriously
// mess up your site's database. Please use with caution and DELETE THIS FILE when you
// are done resetting your website.
// First, get database settings from wp-config.php...
require_once("wp-config.php");
// Create a new database object...
$db=new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
// Was the form submitted?
if (isset($_POST['url'])) {
$url=$_POST['url'];
$query="UPDATE wp_options SET option_value='$url' WHERE option_name='siteurl'";
$result=$db->query($query);
echo "THERE WERE <b>" . $db->affected_rows . "</b> ROWS IN THE DATABASE AFFECTED!<br/><br/>";
// Did the database query update anything? If so, then stop the application...
if ($db->affected_rows != 0) {
die("Be Sure To Delete This File From Your Server When Complete!!!");
}
}
// Query the current information in the database...
$query="SELECT option_value FROM wp_options WHERE option_name='siteurl'";
$result=$db->query($query);
$row=$result->fetch_object();
// Display the form and print out what is in the database...
?>
<form action="sitereset.php" method="post">
<b>Site URL:</b> <input type="text" name="url" size="60" value="<?php echo $row->option_value ?>" />
<br />
<br />
<input type="submit" value="RESET WORDPRESS" />
</form>
D.
THANK YOU SO MUCH! it helps me a lot
March 18, 2009 at 8:28 am
Allan Collins
Glad to hear it.
April 28, 2009 at 4:50 pm
Jakki
Thankyou for this!!
July 20, 2009 at 5:16 am
Jason
YOU ARE A FREAKING GENIUS!!
March 24, 2010 at 10:55 pm
Peter
eeeeeeeeeerrrr .. where is the code guys???
Thanks
June 18, 2010 at 6:37 am
Allan Collins
@Peter – Sorry about that…
June 18, 2010 at 3:54 pm
Luke
Just wanted to say thanks. You saved me a whole afternoon of work.
July 31, 2010 at 10:09 am
Seb
Thanks a lot Allan for providing this trick! I applied it to my web site and it saved me from having to re-install WordPress.
October 11, 2010 at 12:06 am