Last updated on September 13, 2023

Remove Pages from Admin Menu

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Remove pages from the WP Admin menu.

To remove specific pages from the WordPress admin menu, you can use the remove_menu_page() function. This function allows you to remove menu pages by their slug. Here’s an example of how you can achieve this:

function wpsnippets_remove_pages_from_admin_menu() {

    // Array of menu slugs to remove from the admin menu
    $menu_slugs = array( 'edit.php', 'edit-comments.php' );

    // Loop over $menu_slugs
    foreach ( $menu_slugs as $slug ) {
        remove_menu_page( $slug );
    }
}

add_action( 'admin_menu', 'wpsnippets_remove_pages_from_admin_menu' );

In this example, $menu_slugs is an array of menu slugs that correspond to the pages you want to remove from the admin menu. Replace the slugs with the actual slugs of the pages you want to remove.

Inside the wpsnippets_remove_pages_from_admin_menu function, a loop iterates through each menu slug in the $menu_slugs array. The remove_menu_page() function is called with each slug, which removes the corresponding page from the admin menu.

By adding this code snippet to your site, you can remove the specified pages from the WordPress admin menu. Users with the appropriate permissions will no longer see the menu items for the removed pages in the WordPress admin dashboard.

Last updated on September 13, 2023. Originally posted on May 20, 2023.

Leave a Reply