WordPress recovering from a damaged theme – Command Line (via ssh/telnet)

Should you ever need to revert to the default twentysomething theme. After a bodged install, or some other mishap that leaves wp-admin inaccessible, you can do so with a few simple MySQL commands.

Firstly ssh/telnet into your box (if you don’t have ssh/telnet access the same result can be achieved using phpMyAdmin)

Connect to your MySQL server

mysql -u root -p

 Change to the database you want to work on.

use wordpress;

 If you don’t know your database name, you can use;

show databases;

to list out all databases. The default database name is “wp”. But good practise dictates this should have been changed.
Once you have found your database, and used the “use” command, you need to update the options table. Firstly lets see what the theme is set to.

select * from wp_options where option_name = 'template' or option_name = 'stylesheet' or option_name = 'current_theme';

 Outputs;

+-----------+---------------+--------------+----------+
| option_id | option_name   | option_value | autoload |
+-----------+---------------+--------------+----------+
|       144 | current_theme | borkedtheme  | yes      |
|        45 | stylesheet    | borkedtheme  | yes      |
|        44 | template      | borkedtheme  | yes      |
+-----------+---------------+--------------+----------+

The column we are interested in is the “option_value” column, this shows use which theme is currently in use, which template, and which style sheet. All three of these need to be updated in order to change the “theme” the site is using. This is done with three update statements.

update wp_options set option_value = 'twentytwelve' where option_name = 'template';  
update wp_options set option_value = 'twentytwelve' where option_name = 'stylesheet';  
update wp_options set option_value = 'twentytwelve' where option_name = 'current_theme';

 Once run, lets use the prior query to check the changes have taken.

select * from wp_options where option_name = 'template' or option_name = 'stylesheet' or option_name = 'current_theme';

 Outputs;

+-----------+---------------+--------------+----------+
| option_id | option_name   | option_value | autoload |
+-----------+---------------+--------------+----------+
|       144 | current_theme | twentytwelve | yes      |
|        45 | stylesheet    | twentytwelve | yes      |
|        44 | template      | twentytwelve | yes      |
+-----------+---------------+--------------+----------+

 Now reload the site, and you should see the default twentytwelve theme.

 

Wordpress , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *