WordPress Reset : Reset The Site URL

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>




8 Responses to “WordPress Reset : Reset The Site URL”


  1. D.

    THANK YOU SO MUCH! it helps me a lot ;)


    March 18, 2009 at 8:28 am

  2. Glad to hear it.


    April 28, 2009 at 4:50 pm

  3. Thankyou for this!!


    July 20, 2009 at 5:16 am

  4. YOU ARE A FREAKING GENIUS!!


    March 24, 2010 at 10:55 pm

  5. eeeeeeeeeerrrr .. where is the code guys???

    Thanks


    June 18, 2010 at 6:37 am

  6. @Peter – Sorry about that…


    June 18, 2010 at 3:54 pm


  7. Luke

    Just wanted to say thanks. You saved me a whole afternoon of work.


    July 31, 2010 at 10:09 am


  8. 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

Leave a Reply