How to Break a WordPress Install (And Fix It Again)

WordPress is pretty powerful but, sometimes, even this robust CMS can fall victim to humans fiddling with the settings and breaking it. This tutorial and screencast looks at the most common way to break WordPress and what you can do about it.


Changing the Site URL

Sometimes it's tempting to change the Site URL to reflect a change in your domain name. For example, if you're moving from http://oldwebsite.com to http://shinynewwebsite.com, a lot of people who are new to WordPress consider their best, easiest option to be changing the site URL in the Dashboard.

It is important that you do not do this!

This will break your install!

So you've already done it? Not to worry. It's pretty easy to fix. There are actually three ways to fix it.

Option 1 Edit the functions.php File

The first way of fixing your WordPress install is the one preferred by most people. In case you're not familiar with the purpose of a functions.php file, it is mostly used to extend the abilities of your WordPress install or to clean up the code that powers your theme. Your functions file will be different to almost every other theme around.

It doesn't matter too much what is in it because you'll only be using the first couple of lines.

Open up the functions.php file in your theme directory (twentyeleven, etc.). Then at the very top of the file, just after the opening line, put the following in:

Reload your site and it should be fixed. Open up your General dashboard settings and make sure that your Site URL reads as it should (what it was before you edited it).

Important: Don't forget to go back to your functions.php file and remove the lines you just added in. Otherwise you'll keep breaking your site as WordPress will continue to attempt to rewrite the contents of that Site URL field.

Option 2 Edit the wp-config.php File

Another option for resetting the value of your Site URL field, is to update the wp-config.php file which is in the base directory of your site.

Many people, including WordPress' own user manual (The Codex), say that this is not the best choice for resetting the Site URL because it 'hard codes' the Site URL into your WordPress install and doesn't allow you to change it in the Dashboard afterwards.

However, remember how you got into this mess in the first place! It was through someone (or yourself) editing that value thinking it was an easy fix. It might be handy to blank out the option to change it in future.

Additionally, if for some reason Option 1 has failed you, you've really got little choice but to give this a go too!

Open up your wp-config.php file in your editor of choice and look for the line which says: "That's all, stop editing! Happy blogging.". Just below that line, paste in the following, again changing the site URL to whatever your Site URL should be.

Reload your install and it should be fixed. With this method, you may need to type your Site URL into the browser and try to log in using the wp-admin page e.g. http://yourwebsite.com/wp-admin.

Option 3 Relocate, True!

The final way to easily update your Site URL to the correct one is to use WordPress' inbuilt relocate method. This one couldn't be simpler and is very much like the previous method.

Open up your wp-config.php file again and this time, you need to add the following code just above the "That's all, stop editing! Happy blogging." line.

Hey Presto! Your site has found itself again. Just that simple line of code has done a lot (hopefully) to fix your blog. It has updated the appropriate fields within the WordPress database.

Important: Don't forget to go back to your wp-config.php file and remove the line you just added in. Alternatively, if you think you might make the same mistake again in future, you can just change the word 'true' to 'false' (without the speech marks). That way, next time someone changes your Site URL, you can just briefly change it to 'true' again.


That's It!

In conclusion, it's best not to update the Site URL on your blog. If you want to move your site, the best process is to make a backup of your database and theme, before moving the theme files by hand and then importing your existing database into the new Install of WordPress on your new domain name.

Tags:

Comments

Related Articles