最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

singular_name label in custom post type

programmeradmin3浏览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.

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.

Share Improve this question asked Apr 21, 2020 at 4:08 810311810311 417 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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:

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

发布评论

评论列表(0)

  1. 暂无评论