0

I was looking to get more info about 'singular_name' label and came across this link. Based on that link 'singular_name' value should show up when I click 'Add New' and 'Add New Post' window appears. My understanding the value would replace the 'Post' part in the 'Add New Post' title. It's not working for me.

My code

function portfolio_register() {

      $labels = array (
        'name' => __('Portfolio'),
        'singular_name' => __('Project'),
      ); 

      $args = array(

            'labels' => $labels,
            'public' => true,
            'show_ui'=> true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'rewrite' => true,
            'supports' => array('title', 'editor', 'thumbnail') 
          );

          register_post_type('portfolio', $args);

    }

    add_action ('init', 'portfolio_register');

I was able to achive the desired effect using 'add_new' and 'add_new_item' labels, however, was just curious what is the purpose of 'singular_name' label.

1

The answer at that link is incorrect.

The "Edit Animals" text from their answer uses the edit_item label, not singular_name. There's a much longer list of labels that you'll need to provide when registering a post type than just those two. The full list is kept here.

As for singular_name, as far as I can tell, this is only used to label menu items and link suggestions:

menu item labels link suggestions

In both those examples "Page" is where the singular_name is used.

| improve this answer | |
  • Thanks for the quick response Jacob. Your attached screenshot what is it taken from? Is there more info I can get to fully understand the purpose of singular_name or singular_label ? May be some examples of usage? I am not sure if I need singular_label in my code now.. – 810311 Apr 21 at 15:41
  • The menus editor and the links tool in the classic editor. You should provide all the labels in your code. There's no reason not to. I don't know why your take-away from this would be that you don't "need" it. – Jacob Peattie Apr 22 at 1:18
  • Because based on this link developer.wordpress.org/reference/functions/register_post_type $args is an optional parameter. that's the reason I am a bit confused. I am also not sure if I understand how singular_label works as I was not able to find any clear explanation with some examples – 810311 Apr 22 at 1:46
  • It's "optional" only in the pure PHP sense that not providing it won't cause a crash. If you register a post type without args the defaults will all be used. The default post type is not "Portfolio", so you need to provide all the labels with the correct names. – Jacob Peattie Apr 22 at 1:54
  • Thank you for clarification Jacob. I will update my code as per your suggestions. – 810311 Apr 22 at 1:56

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.