Remove post from new menu in top bar

The users can still create new posts if the URL is known, like;
domain.com/wp-admin/post-new.php

Here is the code you can use for that … added it to the file functions.php

function hide_add_new() {
global $submenu;
    // For Removing New Posts from Admin Menu
    unset($submenu['post-new.php?post_type=post'][10]);
    // For Removing New Pages
    unset($submenu['post-new.php?post_type=page'][10]);
   // For Removing CPTs
    unset($submenu['post-new.php?post_type=custom_post_type'][10]);
}
add_action('admin_menu', 'hide_add_new');

//Thanks to Howdy_McGee
function remove_admin_bar_links() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('new-post');
    $wp_admin_bar->remove_menu('new-page');
    $wp_admin_bar->remove_menu('new-cpt');
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );


function disable_new_post() {
if ( get_current_screen()->post_type == 'my_post_type' )
    wp_die( "You ain't allowed to do that!" );
}
add_action( 'load-post-new.php', 'disable_new_post' );

Leave a Comment