How to Disable Theme Changing by Removing Submenu in WordPress

Home » Snippets » How to Disable Theme Changing by Removing Submenu in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

If you’re a WordPress user, you know that there are countless themes available for you to choose from for your website. However, sometimes you may not want your users to have the ability to change the theme of your site. This could be for various reasons – maybe you have a specific design or branding that you want to maintain, or perhaps you want to prevent any potential conflicts or issues that could arise from users constantly changing the theme. In this article, we’ll show you how to disable the option for users to change the theme by removing the appropriate submenu from the WordPress admin dashboard.

					function wpturbo_remove_theme_submenu() {
    global $submenu;
    unset($submenu['themes.php'][5]); // Remove "Themes" submenu
}
add_action('admin_menu', 'wpturbo_remove_theme_submenu');
				

The code snippet above demonstrates how to disable the ability to change themes by removing the "Themes" submenu from the WordPress admin menu.

First, we define a function called wpturbo_remove_theme_submenu(). Within this function, we use the global variable $submenu to access the submenu items of the themes.php menu.

By using the unset() function and passing in the key 5 as an argument, we remove the fifth submenu item, which corresponds to the "Themes" menu. By removing this submenu item, users will no longer be able to access the theme management functionality from the admin menu.

Once we have defined the wpturbo_remove_theme_submenu() function, we then attach it to the admin_menu action using the add_action() function. This ensures that our function is executed when the admin menu is generated.

Upon execution, the wpturbo_remove_theme_submenu() function will remove the "Themes" submenu item, effectively disabling the ability to change themes from the WordPress admin menu.

Register an account to save your snippets or go Pro to get more features.