1

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?

  • 2
    Have you already tried to research the problem or you seek for a free guidance? – Max Yudin Oct 17 '18 at 15:45
  • I think you should proceed locally with a solution like wamp/mamp/lamp :) – benny-ben Oct 17 '18 at 19:10
4

There 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.

|improve this answer|||||
4

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' ] );
|improve this answer|||||
  • This is a nice option if you just need to apply one stylesheet, though if it's truly a new theme doesn't cover all the PHP/markup. :) – WebElaine Oct 17 '18 at 19:11
  • 1
    stylesheet is the option name for the slug of the current theme (or child theme). It would apply the my-new-theme theme (yes, the whole thing) on the front end for logged in users with the activate_plugins capability. – Nathan Johnson Oct 17 '18 at 19:19
  • Oh, nice trick! – WebElaine Oct 17 '18 at 20:08
0

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.)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.