How to customize Wordpress Theme before going live

wordpress, wordpress-theming

Solution

Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the `get_stylesheet` and `get_template` filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.

Here's the code that you need to put in a file in your plugins directory:

<?php 
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).

You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.

Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/

class MyThemeSwitcher {
    private $admin_theme = '';

    function MyThemeSwitcher() {
        add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
        add_filter( 'template', array( &$this, 'get_template' ) );
    }

    function get_stylesheet($stylesheet = '') {
        if ( is_user_logged_in() && $this->admin_theme ) {
            return $this->admin_theme;
        }
        return $stylesheet;
    }

    function get_template( $template ) {
        if ( is_user_logged_in() && $this->admin_theme ) {
            return $this->admin_theme;
        }
        return $template;
    }
}

$theme_switcher = new MyThemeSwitcher();

So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.

Then all you need to do is to update the file(change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-slug';` where `theme-slug` is the name of the directory in which the theme you want to use is).

Also - you won't be able to change the `Front page` and `Posts page` options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).

So if you have no clue whether this solution is for you - well, it depends.

If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).

Problem

Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install. Problem I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this? My Crappy Solution Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this. A better way? I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms `[themes, customization, before installing]`??? Any help is greatly appreciated! Thanks!

Original source