12

I'd like to test some theme changes on my live site, but I obviously don't want regular users seeing any errors that may arise from it. I'd like to just duplicate my theme folder and if I'm logged in as admin, then that theme is shown to me, otherwise, the old theme is shown to my users.

Is there a plugin to do this?

3

2 Answers 2

16

I just wrote this quick plugin and it seems to work. Let me know if there is a better way.

<?php

/*
Plugin Name: Theme Switch if Admin
Description: Display different theme to user if logged in as admin
Author: Kyle Barber
*/
    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;
    }
2
  • Small hint, the plugin User Theme in the official repo have a small plugin for this job, but without options, same solution how this answer.
    – bueltge
    Commented Apr 4, 2013 at 12:39
  • This is an awesome little plugin. Thank you for sharing. Commented Sep 14, 2017 at 16:31
1

You got switch_theme() and current_user_can( 'manage_options' );, which will only trigger for admin accounts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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