Hiding the Posts menu in the WordPress admin

Today we are going to learn about hiding the posts menu in the WordPress admin. We will remove the Posts menu item from the main menu, as well as the New Post menu item from the menu bar.

If you do not want your admin users to see the menu link to create standard posts, you can remove the Posts menu item from the WordPress admin menu. You may want to do this if you are making use of custom posts types via a theme or plugin or do not intend to use a blog on your WordPress site.

Below I will show you how to remove the Posts menu item from the main menu and the New Post menu item from the menu bar.

To remove the Posts menu item from the main menu, add the following code to your theme’s functions.php file.

add_action( 'admin_menu', 'hide_admin_post_main_menu' );
function hide_admin_post_main_menu() {
  remove_menu_page( 'edit.php' );
}

It is worth mentioning that this method does not stop a user accessing these screens. This method is purely aesthetic and is designed to simplify the UI for admin users. If you need to block access to these pages, you will need to use a plugin or some additional code to filter each user’s permissions.

To remove the New Posts menu item from the menu bar, add the following code to your theme’s functions.php file.

add_action( 'admin_bar_menu', 'hide_admin_post_bar_menu', 999 );
function hide_admin_post_bar_menu() {
  global $wp_admin_bar;
  $wp_admin_bar->remove_node( 'new-post' );
}

Hiding the posts menu in the WordPress admin is not crucial, but can allow you to improve the usability of your website’s admin by simplifying the admin UI.

It is usually a good idea to append a namespace to functions you add to your theme’s functions.php file to avoid conflicts with plugins and other code. For example; function adaptive_hide_admin_post_main_menu() {...}.

References