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

Custom Taxonomy's Label to change the text appearing in Appearance > Menu

programmeradmin2浏览0评论

I have three custom post types, each has its own taxonomy like product_cat, event_cat, media_cat. I labeled all of them with the word "Category" like:

register_taxonomy("product_cat", "product", array(
  "labels" => array(
    "name" => "Categories",
    "singular_name" => "Category",
    ...
  ),
  ...
);

But the problem comes when I want to add new Menu in Appearance > Menu tab. You can see it in the picture below:

Is there any label argument to set that into "Product Category", "Event Category"? I can't found it in the codex.

Of course I can always toggle the menu and figure out what it is from the list of terms, but it would be great if I can change that.

Thanks

I have three custom post types, each has its own taxonomy like product_cat, event_cat, media_cat. I labeled all of them with the word "Category" like:

register_taxonomy("product_cat", "product", array(
  "labels" => array(
    "name" => "Categories",
    "singular_name" => "Category",
    ...
  ),
  ...
);

But the problem comes when I want to add new Menu in Appearance > Menu tab. You can see it in the picture below:

Is there any label argument to set that into "Product Category", "Event Category"? I can't found it in the codex.

Of course I can always toggle the menu and figure out what it is from the list of terms, but it would be great if I can change that.

Thanks

Share Improve this question asked Feb 5, 2016 at 3:49 hrsetyonohrsetyono 5792 gold badges5 silver badges17 bronze badges 1
  • 1 Maybe you take a look here custom tax because (imho) it seems you make it yourself more difficult then needed. – Charles Commented Feb 5, 2016 at 18:52
Add a comment  | 

1 Answer 1

Reset to default 1

I'm assuming that you don't want to set different labels for these taxonomies in the first place - you didn't specifically mention that you can't, but I'm assuming the thought occurred to you.

Just in case it didn't, from your code:

register_taxonomy("product_cat", "product", array(
  "labels" => array(
    "name" => "Categories",

Changing "Categories" to "Product Categories" will indeed change the menu label, as well as changing the label in every other relevant place across WordPress.

Now, chances are you knew that but you want it just to be different in the menu section. To do that, you can use the nav_menu_meta_box_object filter. The following should do the job for you, tested on WordPress 4.5.3:

add_action( 'nav_menu_meta_box_object', 'wpse216757_menu_metaboxes' );

function wpse216757_menu_metaboxes ( $tax ){
  if ( $tax->name === 'product_cat' ) {
    $tax->labels->name = "Product Categories";
  }
  return $tax;
}

What this does is takes the taxonomy object and returns a different name for it, only when dealing with the meta boxes on the menu page.

发布评论

评论列表(0)

  1. 暂无评论