3

I have removed the post menu from the admin side bar like so:

add_action('admin_menu','remove_default_post_type');

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

How can I now remove it from the top bar 'new' menu as well?

5

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' );
0

To remove submenus you can inspect the menu you will see every li will have an ID similar to wp-admin-bar-new-content to remove said menu item, just remove wp-admin-bar-. With that we can look at +New -> Post item which has an ID of wp-admin-bar-new-post so we can remove it like so:

function remove_admin_bar_links() {
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu('new-post');
    }
    add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

Reference Link / Tutorial

0
0

Try with the following code :

add_action( 'admin_bar_menu', 'wpse126922_remove_newpost', 999 );

function wpse126922_remove_newpost ( $wp_admin_bar ) {
    $wp_admin_bar->remove_node( 'new-post' );
}
0

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.