I have a milti-site that is set up for contributors to author custom posts. I can't use css to modify the adminbar because it remover the links for all user rolls. How can I remove My Sites, Comment Number and New from the contributor roll adminbar?

  • Quick question before answer, do you want to remove the right to post see comments and create a post to ? Because just hiding buttons on admin bar can be only front restrictive but they continue to have access with URL.
    – Elex
    Dec 10, 2017 at 13:24
  • I want to remove the right to post, see comments and create a post too. I want to remove everything on the admin bar for contributors except for the custom post name, which gets them back and forward to the dashboard and the howdy user name
    – cboy
    Dec 11, 2017 at 20:27

1 Answer 1


When you use register_post_type function, in the second parameter ($args) you can change some parameters.

See the codex for more informations : https://codex.wordpress.org/Function_Reference/register_post_type#Parameters

A good link is also : https://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table to get more information about default capabilites and roles

Here is an example from the docs for "book" custom post type (add this in your $args)

'capabilities' => array(
  'edit_post'          => 'edit_book', 
  'read_post'          => 'read_book', 
  'delete_post'        => 'delete_book', 
  'edit_posts'         => 'edit_books', 
  'edit_others_posts'  => 'edit_others_books', 
  'publish_posts'      => 'publish_books',       
  'read_private_posts' => 'read_private_books', 
  'create_posts'       => 'edit_books', 

You must also add a 'map_meta_cap' in the args :

'map_meta_cap' => true

With this you can set "new" capabilities with the map for your custom post type

function wpse_288266_add_theme_caps() {
    // Add cap for the admins
    $admins = get_role('administrator');

    $contribs = get_role('contributor');
    // Here you remove the rights for other post type without the capabilities mapping
    /* You'll probably want to let them read the posts
add_action('admin_init', 'wpse_288266_add_theme_caps');

To answer about hide some buttons in the admin bar I'll add the role in the body class and add some CSS

function wpse_288266_add_role_body_class($classes) {
    // Get the current user (the action happend when logged in)
    $current_user = new WP_User(get_current_user_id());
    $role = array_shift($current_user->roles);
        $classes .= 'user-role-'. $role;
        $classes[] = 'user-role-'. $role;
    return $classes;

function wpse_288266_add_role_style() {
<style type="text/css" media="screen">
    body.user-role-contibutor #wpadminbar #wp-admin-bar-comments {
        display: none;

    body.user-role-contibutor.single-YOUR_POST_TYPE_KEY #wpadminbar #wp-admin-bar-comments {
        display: list-item;

// We apply our code only for logged-in users
    add_action('wp_footer', 'wpse_288266_add_role_style'); // You can do better directly in your real stylesheet
    add_action('admin_footer', 'wpse_288266_add_role_style');

I actually have no "clean" idea to remove the capability to post a comment for a custom post type :/ Sorry about my English !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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