WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove "Add New" from custom-post-type for Authors (6 posts)

  1. cw17s0n
    Member
    Posted 3 years ago #

    I want to remove all traces of "add new" for my custom-post-type Agents, when viewed by an author. I was looking at custom-post-type capabilities but haven't gotten very far.

    Image of what I want to remove in red outline.

    Thanks

  2. Triple P
    Member
    Posted 3 years ago #

    Check the IDs and classes with Firebug or the like, and hide with css:

    function hide_that_stuff() {
        if('YOURPOSTTYPE' == get_post_type())
      echo '<style type="text/css">
        #favorite-actions {display:none;}
        </style>';
    }
    add_action('admin_head', 'hide_that_stuff');
  3. cw17s0n
    Member
    Posted 3 years ago #

    Thanks that got me part of the way the there, below is the full code I used.

    function remove_submenus() {
      if(!current_user_can('activate_plugins')) {
        global $submenu;
        unset($submenu['edit.php?post_type=agents'][10]); // Removes 'Add New'.
    }
    }
    add_action('admin_menu', 'remove_submenus');
    
    function hide_that_stuff() {
        if('agents' == get_post_type())
      echo '<style type="text/css">
        #favorite-actions {display:none;}
        .add-new-h2{display:none;}
        .tablenav{display:none;}
        </style>';
    }
    add_action('admin_head', 'hide_that_stuff');
  4. Jeff
    Member
    Posted 2 years ago #

    Does this code go into function.php?

  5. cw17s0n
    Member
    Posted 2 years ago #

    Yes, that is where mine is.

  6. Jeff
    Member
    Posted 2 years ago #

    Thanks for sharing!

Topic Closed

This topic has been closed to new replies.

About this Topic