How to Remove the Theme Editor Submenu in WordPress Admin Area

Home » Snippets » How to Remove the Theme Editor Submenu in WordPress Admin Area
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

When working with WordPress, you may not want certain users to have access to the theme editor within the admin area. The theme editor allows users to edit code directly within a theme, which can be risky if someone accidentally makes a mistake. In this article, we’ll show you how to remove the theme editor submenu from the admin area, so that only users with the appropriate permissions can access it.

					function wpturbo_remove_theme_editor_submenu() {
    remove_submenu_page( 'themes.php', 'theme-editor.php' );
}
add_action( 'admin_menu', 'wpturbo_remove_theme_editor_submenu', 999 );
				

The above code creates a new function called wpturbo_remove_theme_editor_submenu(). The purpose of this function is to remove the theme editor submenu from the WordPress admin sidebar menu. Once this function is triggered, WordPress will no longer display the theme editor as a submenu item under the Themes menu.

To complete this operation, the code utilizes the remove_submenu_page() function. This function accepts two parameters: the first parameter is the parent menu slug (themes.php), and the second parameter is the submenu page slug to remove (theme-editor.php).

Note that the add_action() function is used to hook the wpturbo_remove_theme_editor_submenu() function to the admin_menu action. The third parameter for this function is the priority of the function which in this case is set to 999. This ensures that the function is run after all other plugin and theme functions have been executed.

Overall, by utilizing the remove_submenu_page() function within the wpturbo_remove_theme_editor_submenu() function and using the appropriate parameters, the code successfully removes the theme editor submenu from the WordPress admin sidebar menu.

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