How to deploy a new theme/theme options from staging to production site

There are a number of options that depend on your level of comfort with code and the number of changes you need to make. There are also a number of ways to achieve the same result. You mention partial migrations. If you can do that, go with it. That’s the fastest.

I’m going to cover how I would handle this. It’s not the right or wrong answer, but just my perspective. This process assumes some potential downtime while you’re doing the deployment. There are other options for high-availability websites that can be far more complex, so I won’t cover those here.

Track your changes

While you’re developing try to have any database changes in code if you can. For example, if you have custom fields, post types, taxonomies, make sure you have these registered as a part of the theme. Include default variables in here as well.

Create a migration script

For bigger changes, start a WP CLI script (or plugin) to roll out and roll back your migration. This is useful for importing new content, moving content, or altering taxonomies.

BACK UP YOUR DATA

Before you run anything, make sure you have a backup. Losing your work is tough, but losing customer data is detrimental.

Run everything on a staging environment

Once you’re ready, set up a staging environment with your new code (from your dev environment) and your production database. You should do the minimum database changes required to get this set up (usually only search-replace). When you push this live the site will be in this state: new code without any database changes to support it.

From there, start your migration scripts and make sure everything executes smoothly. Make sure you haven’t lost any data and that nothing is broken. Then run your roll back scripts to make sure you can undo everything you’ve done. Always test these scripts to make sure if something goes wrong you can get back to where you were quickly.

If you run into a problem, rerun this process until everything works without a hitch.

Repeat

Do the same thing on your production environment. You will probably want to put the site in maintenance mode while you’re running these scripts to prevent any errors or user complaints.

Leave a Comment