How to remove a submenu page in WordPress using remove_submenu_page
The remove_submenu_page
function in WordPress is used to remove a specific submenu page from the admin menu. This can be useful for customizing the admin menu to only show the necessary pages for a specific user role or to simplify the menu for a cleaner user experience.
By using the remove_submenu_page
function, developers can tailor the WordPress admin menu to better suit the needs of their clients or users, ensuring that only relevant and essential pages are easily accessible.
Parameters Accepted by the WordPress remove_submenu_page Function
The remove_submenu_page
function accepts the following parameters:
$menu_slug
(string, required): The slug for the parent menu.$submenu_slug
(string, required): The slug of the submenu.
Value Returned by the WordPress remove_submenu_page Function
The remove_submenu_page
function returns the following:
array|false: The removed submenu on success, false if not found.
Examples
How to remove a submenu page in WordPress
Use the remove_submenu_page
function to remove a submenu page from the WordPress admin menu.
if ( ! current_user_can( 'manage_options' ) ) {
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
}
How to remove multiple submenu pages in WordPress
Use the remove_submenu_page
function multiple times to remove multiple submenu pages from the WordPress admin menu.
if ( ! current_user_can( 'manage_options' ) ) {
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );
}
Conclusion
In conclusion, the remove_submenu_page
function is a valuable feature for customizing the WordPress admin menu to fit the specific needs of a website or application. By using this function, developers can easily remove unwanted submenu pages and streamline the user experience for administrators. This function provides a straightforward way to declutter the admin menu and ensure that only relevant options are available. Additionally, the ability to target specific user roles adds an extra layer of flexibility and control. Overall, the remove_submenu_page
function is a valuable resource for WordPress developers looking to tailor the admin experience to their unique requirements.
Related WordPress Functions
- Adding an options page to the WordPress admin menu with add_options_page
- Using add_plugins_page to create a custom plugin page in WordPress
- How to remove a menu page from the WordPress dashboard
- Adding a subpage to the WordPress admin menu with add_submenu_page
- Adding a custom admin menu page in WordPress using add_menu_page