1

I need to 'soft' disable posts in a WordPress site. By that I mean I am hiding the 'Posts' menu item from admin... and not much else.

I would also like to disable 'posts' from appearing in the Menu admin. This can already be turned off by deselecting it from 'Screen Options', but is there a way to do this programmatically and, as a bonus, also hide the 'posts' checkbox from the Screen Options panel?

2

We can use the register_post_type_args filter to adjust how the post post type is displayed in the backend with e.g.:

add_filter( 'register_post_type_args', function( $args, $name )
{
    if( 'post' === $name )
    {   
        // $args['show_ui']        = false; // Display the user-interface
        $args['show_in_nav_menus'] = false; // Display for selection in navigation menus
        $args['show_in_menu']      = false; // Display in the admin menu
        $args['show_in_admin_bar'] = false; // Display in the WordPress admin bar
    }
    return $args;
}, 10, 2 );

More info on the parameters here in the Codex.

  • Dunno how WP evolved in the past few years, but ~10 years ago this wouldn't have been enough: the pages would still be available if you enter the url. If you need to disable those as well, the better way of doing this back then was to remove post-related permissions. – Denis de Bernardy Jul 5 '17 at 17:23
  • 1
    That's a good concern but in this case the OP mentioned I need to 'soft' disable posts in a WordPress site. By that I mean I am hiding the 'Posts' menu item from admin... and not much else. so I understood it as only hiding it and still allow accessing it via url (that's also why I originally commented out show_ui as false) For the "hard" disabled case I would suggest other approach, like you mentioned. @DenisdeBernardy – birgire Jul 5 '17 at 17:32
1

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

function posts_hide()      //creating functions post_remove for removing menu item
{ 
   remove_menu_page('edit.php');
}

add_action('admin_menu', 'posts_hide');   //adding action for triggering function call

Hope this solves you query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.