wordpress

How to remove posts from admin sidebar in wordpress


I was wondering how to remove the posts section from the wordpress admin sidebar (see image below) Wordpress Posts


Solution

  • you will be needing to edit functions.php for this and add some code in that. This section of posts lies as edit.php

    See the official wordpress codex documentation for remove_menu_page() function to understand better. Doc states function usage as:

    <?php remove_menu_page( $menu_slug ) ?>
    

    Here $menu_slug is edit.php for post menu.

    Now create your own function called post_remove() and add code in functions.php as:

    function post_remove () 
    { 
       remove_menu_page('edit.php');
    } 
    

    The next part is to hook your post_remove() function with a specific action which in this case is admin_menu to trigger this function. For that, add some more code in functions.php:

    add_action('admin_menu', 'post_remove');
    

    So in short, following is complete code that you need to add in your functions.php file:

    function post_remove ()      //creating functions post_remove for removing menu item
    { 
       remove_menu_page('edit.php');
    }
    
    add_action('admin_menu', 'post_remove');   //adding action for triggering function call
    

    Official documentation links

    http://codex.wordpress.org/Function_Reference/remove_menu_page http://codex.wordpress.org/Function_Reference/add_action