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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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;
}
Method 2
You got switch_theme() and current_user_can( 'manage_options' );, which will only trigger for admin accounts.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0