How to Backup WordPress Theme? (4 Simple Ways)

Feb 9, 2021

How to Backup WordPress Theme? (4 Simple Ways)

Feb 9, 2021

WordPress themes are designed to be flexible so that they can be easily customised to suit individual websites. Chances are that you’ve customized your WordPress theme either for better form or function as well.

If something happens to your website, then you can’t just download the theme and upload it again. Every bit of customisation you did will be lost and you’ll have to do it from scratch. So, you should backup WordPress theme just in case you ever need to restore your website.

A child theme doesn’t work as a valid backup. Child themes will protect your customisation when you update the theme. But if your server crashes for some reason, you’ll most likely lose everything. Nonetheless, if you’re using a child theme, we suggest you back that up as well.

But, how to backup theme in WordPress? In this article, we’ll talk about 4 simple ways to backup WordPress theme. 

Let’s dive in.


TL;DR: Use BlogVault to take a quick backup of your entire website. A backup of your theme files won’t help you restore the full website. For that, you need all files and databases. BlogVault will help you do just that.

How to Backup WordPress Theme using BlogVault?

To be clear, taking a backup with a plugin is the only process that we recommend. If you’re not sure which plugin to choose, this guide on best WordPress backup plugins will help you out. The other methods all have certain risks (more on this later).

BlogVault doesn’t only backup your WordPress theme files. The plugin takes a full backup of your entire website — files, database, and all. In the event that your website goes down, having a backup of your theme is useless. You can’t restore your website using only your theme.

If you’re not already a BlogVault customer, don’t worry. All you need to do is install the plugin:

After that, the plugin will create a dashboard for you where you can manage and store all your backups.

WordPress theme backup using Blogvault backup plugin

The best part? You don’t even have to do anything after installing the plugin. BlogVault automatically syncs with your website and takes a daily backup on autopilot.

You also can take additional backups whenever you want with one click:

Blogvault automatically sync with WordPress site and take daily backups

If you ever need to restore your website, you can do that from the dashboard with one click as well.

And that’s all there is to it. Use BlogVault to take a quick backup of your website right away.

How to take WordPress Theme Backup using FTP?

Using FTP clients is a simple and straightforward way to backup WordPress theme. That said, there are some risks involved with this process (more on this later).

Here’s how you can download a copy of your WordPress theme locally using an FTP client:

Step #1: Connect to your website using an FTP client like FileZilla

We won’t teach you how to use an FTP client. If you need help with that, here’s a link that shows you how to use FileZilla.

We recommend using BlogVault to take a backup instead.

Step #2: Head to wp-content/themes

By default, all your themes get uploaded and stored in the wp-content/themes folder.

theme backup in WordPress using FTP

Download the activated theme on your PC and make sure that the FTP client says “file transferred correctly”.

And that’s all there is to it.

Warning:

Using FTP to take a backup of anything on your website is never a good idea. For one thing, there’s a huge risk of you losing the backup file or accidentally deleting it. There are also storage issues, but they’re not that severe if you’re backing up only your WordPress theme.

The biggest risk, however, is that you accidentally delete something on your website while you’re connected to it using an FTP client.

How to Backup WordPress Theme using Theme Editor?

This is a very simple, copy-paste trick. But you have to do it right. If you miss out on some files or some block of code, the theme backup won’t work when you try to restore it.

Head over to the Theme Editor on your WordPress dashboard:

Theme editor in dashboard

In the Theme Editor, you’ll see a bunch of editable PHP files:

Backup WordPress theme using theme editor

Now, copy and paste the code to a file on Notepad++ or some similar editor. Then, and this is important, name your Notepad++ file the same as the actual PHP file. For instance, if you’re copying the functions.php file, then name your copy functions.php as well.

Do this for all the theme files and you have a backup of your theme.

Of course, this is a very tedious process and can take a good deal of time.

Warning:

If you accidentally miss even so much as a semi-colon in there while copying, then the entire work goes down the drain. So, naturally, we don’t recommend this process either.

How to backup and restore theme options in WordPress with code

Head to the functions.php file in your Theme Editor.

Then, paste this code snippet at the bottom of functions.php:

/*
	Backup/Restore Theme Options
	Go to "Appearance > Backup Options" to export/import theme settings
*/
class backup_restore_theme_options {

	function backup_restore_theme_options() {
		add_action('admin_menu', array(&$this, 'admin_menu'));
	}
	function admin_menu() {
		// add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
		// $page = add_submenu_page('themes.php', 'Backup Options', 'Backup Options', 'manage_options', 'backup-options', array(&$this, 'options_page'));

		// add_theme_page($page_title, $menu_title, $capability, $menu_slug, $function);
		$page = add_theme_page('Backup Options', 'Backup Options', 'manage_options', 'backup-options', array(&$this, 'options_page'));

		add_action("load-{$page}", array(&$this, 'import_export'));
	}
	function import_export() {
		if (isset($_GET['action']) && ($_GET['action'] == 'download')) {
			header("Cache-Control: public, must-revalidate");
			header("Pragma: hack");
			header("Content-Type: text/plain");
			header('Content-Disposition: attachment; filename="theme-options-'.date("dMy").'.dat"');
			echo serialize($this->_get_options());
			die();
		}
		if (isset($_POST['upload']) && check_admin_referer('shapeSpace_restoreOptions', 'shapeSpace_restoreOptions')) {
			if ($_FILES["file"]["error"] > 0) {
				// error
			} else {
				$options = unserialize(file_get_contents($_FILES["file"]["tmp_name"]));
				if ($options) {
					foreach ($options as $option) {
						update_option($option->option_name, unserialize($option->option_value));
					}
				}
			}
			wp_redirect(admin_url('themes.php?page=backup-options'));
			exit;
		}
	}
	function options_page() { ?>

		<div class="wrap">
			<?php screen_icon(); ?>
			<h2>Backup/Restore Theme Options</h2>
			<form action="" method="POST" enctype="multipart/form-data">
				<style>#backup-options td { display: block; margin-bottom: 20px; }</style>
				<table id="backup-options">
					<tr>
						<td>
							<h3>Backup/Export</h3>
							<p>Here are the stored settings for the current theme:</p>
							<p><textarea class="widefat code" rows="20" cols="100" onclick="this.select()"><?php echo serialize($this->_get_options()); ?></textarea></p>
							<p><a href="?page=backup-options&action=download" class="button-secondary">Download as file</a></p>
						</td>
						<td>
							<h3>Restore/Import</h3>
							<p><label class="description" for="upload">Restore a previous backup</label></p>
							<p><input type="file" name="file" /> <input type="submit" name="upload" id="upload" class="button-primary" value="Upload file" /></p>
							<?php if (function_exists('wp_nonce_field')) wp_nonce_field('shapeSpace_restoreOptions', 'shapeSpace_restoreOptions'); ?>
						</td>
					</tr>
				</table>
			</form>
		</div>

	<?php }
	function _display_options() {
		$options = unserialize($this->_get_options());
	}
	function _get_options() {
		global $wpdb;
		return $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name = 'shapeSpace_options'"); // edit 'shapeSpace_options' to match theme options
	}
}
new backup_restore_theme_options();

And that’s all there is to it.

What this code does is create a very simple backup and restore option to your theme directly. This is not a good idea any way you slice it. Sure, it’s free. But there’s no telling how different themes may process this new code. 

Also, there’s absolutely no guarantee that the backups will actually work. It depends partly on the server’s resources how well the backup process will run.

To make things even worse, to take an actual backup, you’ll have to have access to the WordPress dashboard. So, in the event of a server crash, you’ll definitely lose a lot of data unless you keep taking a WordPress theme backup every time you make a change or update the theme because it’s not an automated backup process.

Final thoughts

That’s pretty much about how to backup WordPress theme.

If you’re a BlogVault customer, then you won’t have any of the hassle involved with traditional backups that are highly likely to fail. So, if you’re already using BlogVault to backup your website, you’re free to focus on your business instead of waiting for something to go wrong with your website like other people. You can also go through our guide on how to backup WordPress site for complete backup.

And if you’re not using a reliable backup service like BlogVault, we hope that the alternate methods listed in this article helped you in some way. None of the other methods are sustainable, but if you needed something quick and dirty, we hope you got it.