Add label to custom post type

Posted in: Newspaper
Post count: 33

Hello,

I’m using a custom post type (like your example td_books…) and I would have the possibility to add a label:
as in WP backend clicking on “Posts” the 2nd level menu displays “All posts”, in my CPT named “Giocatori” on the 2nd level menu I have the same “Giocatori”, but I need to have “Tutti i giocatori”.
How can I do?

Thanks

Here is the code I’m using inside functions.php:

// to register Custom Post Types and taxonomies, the use of the init hook is required!
add_action(‘init’, ‘custom_post_type_init’);
function custom_post_type_init() {

/**
* add the td_book custom post type
* https://codex.wordpress.org/Function_Reference/register_post_type
*/
$args = array(
‘public’ => true,
‘label’ => ‘Giocatori’,
‘supports’ => array( // here we specify what the taxonomy supports
‘title’,
‘editor’,
‘thumbnail’,
‘excerpt’,
‘comments’
),
//’taxonomies’ => array(‘category’) // if you also want to add an existing taxonomy like categories or tags, you can add them here
);
register_post_type( ‘giocatori’, $args );

/**
* Add new taxonomy, make it hierarchical (like categories) and associate it to the td_books Custom Post Type
* https://codex.wordpress.org/Function_Reference/register_taxonomy
*/
$labels = array(
‘name’ => _x( ‘Ruolo’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Ruolo’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Cerca ruoli’ ),
‘all_items’ => __( ‘Tutti i ruoli’ ),
‘parent_item’ => __( ‘Ruolo genitore’ ),
‘parent_item_colon’ => __( ‘Ruolo genitore:’ ),
‘edit_item’ => __( ‘Modifica ruolo’ ),
‘update_item’ => __( ‘Aggiorna ruolo’ ),
‘add_new_item’ => __( ‘Aggiungi nuovo ruolo’ ),
‘new_item_name’ => __( ‘Nome nuovo ruolo’ ),
‘menu_name’ => __( ‘Ruolo’ ),
);
$args = array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘ruolo’ ),
);
register_taxonomy( ‘ruolo’, array(‘giocatori’), $args );

/**
* Add new taxonomy, NOT hierarchical (like tags) and associate it to the td_books Custom Post Type
* https://codex.wordpress.org/Function_Reference/register_taxonomy
*/
$labels = array(
‘name’ => _x( ‘Tag’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Tag’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Cerca tag’ ),
‘popular_items’ => __( ‘Tag popolari’ ),
‘all_items’ => __( ‘Tutti i tag’ ),
‘parent_item’ => null,
‘parent_item_colon’ => null,
‘edit_item’ => __( ‘Modifica tag’ ),
‘update_item’ => __( ‘Aggiorna tag’ ),
‘add_new_item’ => __( ‘Aggiungi nuovo tag’ ),
‘new_item_name’ => __( ‘Nome nuovo tag’ ),
‘separate_items_with_commas’ => __( ‘Separa i tag con delle virgole’ ),
‘add_or_remove_items’ => __( ‘Aggiungi o rimuovi tag’ ),
‘choose_from_most_used’ => __( ‘Scegli un tag tra quelli più utilizzati’ ),
‘not_found’ => __( ‘Nessun tag trovato.’ ),
‘menu_name’ => __( ‘Tag’ ),
);
$args = array(
‘hierarchical’ => false,
‘labels’ => $labels,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘update_count_callback’ => ‘_update_post_term_count’,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘tag’ ),
);
register_taxonomy( ‘tag’, ‘giocatori’, $args );

}

Post count: 20685

Hi,

That would be the name of registered the custom post type. I see that the custom post type name you use is ‘label’ => ‘Giocatori’ so that will be the sub-menu name as well. You could try the example solution provided here
https://wordpress.stackexchange.com/questions/66102/custom-post-type-menu-namee
Modify your code accordingly, I have tried it like this
https://www.screencast.com/t/OzzxyYjMW
https://www.screencast.com/t/s7vuOlf3gv

Thanks

Post count: 33

Hi Simion,

yes, perfect!

Thank you very much

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.