How to Disable Theme Switching from the WordPress Dashboard
Sometimes clients can mess with or even break their WordPress site. One of the ways they’ll do this is by changing their WordPress theme – this can easily be prevented with a little PHP.
How to Disable WordPress Theme Switching
Paste the following code in your WordPress Theme’s functions.php to completely disable WordPress theme switching and save clients from themselves.
// disable theme switching add_action( 'admin_init', 'wplg_lock_theme' ); function wplg_lock_theme() { global $submenu; unset( $submenu['themes.php'][5] ); unset( $submenu['themes.php'][15] ); }
How to Disable WordPress Theme Switching – Except for Whoever Setup the Site
Paste the following code in your WordPress Theme’s functions.php to only let the user with the ID #1 change themes – and the user with the ID #1 is the person who setup the site, which is usually the developer. If you have a different user ID, simply change the number to your user ID so you’re the only one who can change the theme.
// disable theme switching add_action( 'admin_init', 'wplg_lock_theme' ); function wplg_lock_theme() { global $submenu, $userdata; get_currentuserinfo(); if ( $userdata->ID != 1 ) { unset( $submenu['themes.php'][5] ); unset( $submenu['themes.php'][15] ); } }
It’s also worth noting that only users with the “Administrator” level can change the theme. So it’s also perfectly valid to give clients the “Editor” capability. More info on WordPress’ user levels.