Disable WordPress theme changing

You’ve probably spent a lot of hours customizing the site’s theme, maybe even built it from the ground up to meet your client’s very specific needs. Either way, if you client swapped the theme it could spell disaster.

Luckily, there’s another handy code snippet you can use to remove the “Themes” menu item under “Appearances” in the admin sidebar. Just add this code to your functions.php file:

add_action( 'admin_init', 'slt_lock_theme' );
function slt_lock_theme() {
global $submenu, $userdata;
if ( $userdata->ID != 1 ) {
unset( $submenu['themes.php'][5] );
unset( $submenu['themes.php'][15] );

This code will hide the Themes sub-menu from all users other than user ID 1, who is usually the person who setup the site. This allows only the site’s creator to edit the site without having to keep editing the functions.php file.

Written By

Panagiotis (pronounced Panayotis) is a passionate G(r)eek with experience in digital analytics projects and website implementation. Fan of clear and effective processes, automation of tasks and problem-solving technical hacks. Hands-on experience with projects ranging from small to enterprise-level companies, starting from the communication with the customers and ending with the transformation of business requirements to the final deliverable.