Disable Posts Post Type

This WordPress code snippet is useful if you want to disable the “Posts” post type in the WordPress admin. This could be handy in situations where you’re using WordPress as a CMS for a site that doesn’t require blog posts, but instead only uses pages or custom post types.

The remove_menu_page function is used to remove the “Posts” link in the admin menu. This function is hooked to the ‘admin_menu’ action, which is called after the basic admin panel menu structure is in place.

The remove_node method of the $wp_admin_bar object is used to remove the “New Post” link in the WordPress admin bar. This method is called within a function hooked to the ‘admin_bar_menu’ action, which is used to add nodes to the admin bar.

Finally, the remove_meta_box function is used to remove the “Quick Draft” widget from the dashboard. This function is hooked to the ‘wp_dashboard_setup’ action, which is fired after all default WordPress dashboard widgets have been registered.

This snippet is ready to use as is. After adding this snippet to your functions.php file or a site-specific plugin, the “Posts” post type will be effectively hidden in the WordPress admin. It’s important to note that this does not actually unregister the “Posts” post type or delete any existing posts; it simply hides the related UI elements in the admin. If you need to actually unregister the post type, more advanced code would be required.

PHP
// Remove side menu
add_action( 'admin_menu', function () {
	remove_menu_page( 'edit.php' );
} );
// Remove +New post in top Admin Menu Bar
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
	$wp_admin_bar->remove_node( 'new-post' );
}, 999 );
// Remove Quick Draft Dashboard Widget
add_action( 'wp_dashboard_setup', function () {
	remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
}, 999 );