I am working on updating our current website and would like to build a new theme without disturbing the current site. How should I go about doing this? Can I just add the theme and then not make it active until I'm ready?
I am working on updating our current website and would like to build a new theme without disturbing the current site. How should I go about doing this? Can I just add the theme and then not make it active until I'm ready?
Share Improve this question asked Oct 17, 2018 at 15:23 Alex EichenmullerAlex Eichenmuller 191 bronze badge 2- 2 Have you already tried to research the problem or you seek for a free guidance? – Max Yudin Commented Oct 17, 2018 at 15:45
- I think you should proceed locally with a solution like wamp/mamp/lamp :) – benny-ben Commented Oct 17, 2018 at 19:10
3 Answers
Reset to default 4There are a couple of options.
One: there are plugins that will let just certain logged-in users see the site in a different theme. You could use one of these and enable the new theme for yourself until you're ready to make the switch.
Two: copy your site onto a staging site and experiment there. The biggest potential downside is that if the theme has any settings, you'll have to go make those on the live site when you're ready to make the switch. However, if your theme has a lot of settings, this may be your only option - you'll have to look at the plugins and see whether they allow you to configure multiple themes.
You can use the pre_option_stylesheet
filter to dynamically change the stylesheet. In the following example, I show the default stylesheet selected on WordPress admin to regular users and a different theme with the slug my-new-theme
to users with the activate_plugins
capability.
/*
* Plugin Name: WPSE Theme Switch Example
* Description: Show `my-new-theme` to users with the `activate_plugins` capability.
* Required PHP: 5.4
*/
namespace StackExchange\WordPress;
class stylesheet {
protected $theme = 'my-new-theme';
public function get_theme( $theme ) {
return $this->show_new_theme() ? $this->theme : $theme;
}
protected function show_new_theme() {
return ! \is_admin() && \current_user_can( 'activate_plugins' );
}
}
\add_filter( 'pre_option_stylesheet', [ new stylesheet(), 'get_theme' ] );
A comment to the question said to 'develop locally'. Proceeding locally may allow you to develop and tweak the new theme, but then how do you get the new theme's settings to the site? You can't just copy the database; that will overwrite content.
So, I would add to that: develop locally until you have the new theme tweaked the way you want. Then there are plugins that allow you to export and import theme settings without affecting the site's content. Install the new theme on the site (but don't activate), and then import the settings from your development system. Then activate the new theme and test thoroughly.
The advantage to this, I believe, is that you can tweak without worrying that you might cause problems with the live site.
Of course, if the new site is going to use new plugins, then there will be an issue with plugin settings. Not many plugins have a setting import/export, so you will have to carefully document your plugin settings so you can duplicate on the live site.
(I haven't looked, but perhaps there is a plugin that exports/import other plugin's settings.That would be nifty.)