Renaming Menu Item within Admin Menu Section for a Custom Post Type?

I have a feeling this is a bug.

When you create a new custom post type it does not seem possible to modify the first submenu item text. I am referring to the link which allows you to view the post list.

Read More

For what I can tell it just seems to be duplicating the name name of the main post type menu which was created.

Does anyone know how to modify this text so that I can have the main menu element says “Articles” and the post list submenu name to say “Manage Articles”?

I was under the impression that "edit_item" would control the text to be displayed in te submenu but for some reason this is not registering.

Here is the code I am currently using:

//////////////////////////////////////////////////////////////////////////////
// CUSTOM POSTTYPE FOR -- ARTICLES  
//////////////////////////////////////////////////////////////////////////////

add_action('init', 'articles');
function articles() {
 register_post_type('articles', array(
  'labels' => array(
   'name'   => __('Articles'),
   'singular_label'  => __('Article'),
   'new_item'   => __('Add Article'),
   'add_new'   => __('Add Article'),
   'add_new_item'  => __('Add Article'),
   'edit'   => __('Edit Article'),
   'edit_item'   => __('Edit Article'),
   'view'   => __('View Article'),
   'view_item'   => __('View Article'),
   'search_items'  => __('Search Articles'),
   'not_found'   => __('No Articles Found'),
   'not_found_in_trash' => __('No Articles Found in Trash'),
   ),
  'supports' => array(
   'thumbnail',
   'title',
   'editor',
   'author',
   'revisions',
   ),
  'rewrite' => array( 
   'slug'   => 'articles', 
   'with_front'   => false,
   ),
  'rewrite'    => true,
  'can_export'    => true,
  'show_ui'    => true,
  'menu_position'   => 3,
  'public'    => true,
  'query_var'    => true,
  'publicly_queryable'  => true,
  'exclude_from_search'  => false,
  'capability_type'   => 'post',
  'hierarchical'   => false,
 ));
 }


add_filter('manage_edit-articles_columns', 'add_new_articles_columns');
function add_new_articles_columns($articles_columns) {
 $new_columns['cb']     = '<input type="checkbox" />';
 $new_columns['article_thumbnail']   = _x('Image', 'column name');
 $new_columns['title']    = _x('Article Title', 'column name');
 $new_columns['article_excerpt']   = _x('Article Excerpt', 'column name');
 $new_columns['article_source']   = _x('Article Source', 'column name');
 $new_columns['author']    = __('Created by');
 $new_columns['date']    = _x('Last Action', 'column name');
 return $new_columns;
 }
add_action('manage_posts_custom_column', 'manage_articles_columns', 10, 2);
function manage_articles_columns($column_name, $id) {
 global $wpdb;
 switch ($column_name) { 
  case 'article_thumbnail':  
   the_post_thumbnail( array(50,50) );
   break; 
  case 'article_excerpt': echo substr(get_the_excerpt(),0,500); 
   break;
  case 'article_source':
         echo get_the_term_list($post->ID, 'content_sources', '', ', ','');
   break;
  default: break;
  }
 }

Related posts

Leave a Reply

2 comments

  1. Hi @NetConstructor.com:

    I think you already asked about this and I gave you an answer that would address this question too:

    In that answer I gave you a library you can use to make interacting with the admin menus super easy. Here’s what you’d have to do to achieve your stated goal on this question:

    <?php
    require_once('wp-admin-menu-classes.php');
    add_action('admin_menu','my_admin_menu');
    function my_admin_menu() {
      rename_admin_menu_section('Articles','Manage Articles');`  
    }
    

    P.S. BTW, I noticed there were 4 answers provided on that question which you asked almost a week ago, but you haven’t gone back an selected any of the answers as the correct answer. Since you have been here asking a lot of questions I know it’s not like you’ve not been around; please take time to select the best answer for your questions as soon as you have a viable answer otherwise people might become demotivated to keep answering. Something this consider…

  2. This is a semantics problem.

    'edit_item'   => __('Edit Article'),
    

    This is what is displayed when you edit the article, as in singular, just like the edit post, in the top title. The reason that the ‘posts’ listing menu item is called ‘posts’ and not ‘edit posts’ is because that would be misleading.

    You can do more than just edit posts, you can delete and move them around etc. The same is true of pages, or any other type of post you may have. This is why the same field that is used for the section menu is used for the initial submenu item also. There is real logic to it. Having said that there is nothing stopping you from setting 'show_ui' => true, to false and implementing it yourself.

    However, if you really did want to edit it for whatever reason, you would need to add a hook to functions.php to process the menu afterwards, by searching for the necessary submenu entry in the array and changing its name.

    Something along these lines would do, though it may need some modification:

    function edit_menus() {
        global $menu;
        end ($menu);
        while (prev($menu)){
            $value = explode(' ',$menu[key($menu)][0]);
            if(strpos($menu[key($menu)], "menu name" )){
                $menu[key($menu)] = str_replace("menu name", "newmenuname", $menu[key($menu)]);
                break;
            }
        }
    }
    add_action('admin_menu', 'edit_menus');