Show A Different Theme For Admin Without A Plugin

Switching to a different theme as Admin is a convenient way to create a new theme or edit an existing theme without having to take your site offline while making edits.  Visitors to your site will continue to see the original theme while you work in the background.

If you would like the ability to switch to a different theme when logged in as administrator, you can simply add a small amount of code to your functions file.  Modify the $theme variable to match the name of the theme you would like to work on.

<?php

/*
Plugin Name: Theme Switch if Admin
Description: Display different theme to user if logged in as admin
Author: Kyle Barber
Source: https://wordpress.stackexchange.com/questions/49223/show-different-theme-for-admin
*/
    add_filter('template', 'change_theme');
    add_filter('option_template', 'change_theme');
    add_filter('option_stylesheet', 'change_theme');
    function change_theme($theme) {
        if ( current_user_can('manage_options') ) {
            $theme = 'twentyeleven';
        }

        return $theme;
    }

To make edits on your existing theme, create a duplicate folder of the theme and rename it (ie mytheme => mytheme-test).  Then upload it to your themes directory.

The downside to this method is that you’ll likely only see changes made to your style.css and functions.php files due to site caching.  To override this, you’ll need to disable caching while you edit other files.

You can confirm this is functioning as intended by opening your site in an Incognito window to verify that anonymous visitors are presented with the original theme.

Available for Amazon Prime