How to Remove Theme Editor Submenu in WordPress

Home » Snippets » How to Remove Theme Editor 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

The Theme Editor in WordPress can be a helpful tool for developers who need to make changes directly to their theme files. However, if you’re worried about the potential of accidentally breaking your site by making a wrong adjustment, removing access to the Theme Editor can be a smart move. Or perhaps, you may want to remove it to ensure less tech-savy clients from tampering with theme code. Whatever your reason might be, this article will guide you through the simple steps to remove the Theme Editor submenu from your WordPress dashboard.

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

The code snippet provided is designed to remove the theme editor submenu from the WordPress admin dashboard. Here’s a complete run-down of how exactly this piece of code works.

The initial portion of the code presents a specific function named wpturbo_remove_theme_editor_submenu(). This function will be used to accomplish the task of removing the theme editor submenu.

In the context of this function, the remove_submenu_page() WordPress built-in function is used. This built-in function takes in two parameters: the parent menu slug and the submenu slug. In this case, ‘themes.php’ is the parent menu slug, and ‘theme-editor.php’ is the slug of the submenu we wish to remove. Together, these parameters provide the necessary information to identify and remove the theme editor submenu from the dashboard.

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

In the final part of the code, an action hook is added using the add_action() function. This function links the wpturbo_remove_theme_editor_submenu() function to the ‘admin_init’ hook, which runs when the WordPress admin area initializes. This ensures that the function will be executed whenever the WordPress admin area is loaded, thus effectively removing the theme editor submenu from the WordPress admin dashboard every time.

add_action( 'admin_init', 'wpturbo_remove_theme_editor_submenu' );

So, in short, this function firstly identifies the theme editor submenu using the slugs, and then, with the help of the add_action() function, ensures that the theme editor submenu is removed each time the WordPress admin area initializes.

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