REFACTOR Update custom taxonomy registration to improve structure and labels

This commit is contained in:
Antoine 2025-05-12 16:54:36 +02:00
parent 065d4f11bd
commit 01a687e468

View File

@ -1,30 +1,44 @@
<?php <?php
function add_custom_taxonomies() {
register_taxonomy('thematiques', 'post', array(
// 'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI // Register Custom Taxonomy
'labels' => array( function custom_taxonomy()
'name' => _x( 'Thématiques', 'taxonomy general name' ), {
'singular_name' => _x( 'Thématique', 'taxonomy singular name' ),
'search_items' => __( 'Chercher une Thématique' ), $labels = array(
'all_items' => __( 'Toutes les Thématiques' ), 'name' => _x('Taxonomies', 'Taxonomy General Name', 'text_domain'),
'parent_item' => __( 'Thématique Parent' ), 'singular_name' => _x('Taxonomy', 'Taxonomy Singular Name', 'text_domain'),
'parent_item_colon' => __( 'Thématique Parent:' ), 'menu_name' => __('Taxonomy', 'text_domain'),
'edit_item' => __( 'Editer la Thématique' ), 'all_items' => __('All Items', 'text_domain'),
'update_item' => __( 'Mettre à jour la Thématique' ), 'parent_item' => __('Parent Item', 'text_domain'),
'add_new_item' => __( 'Ajouter une Thématique' ), 'parent_item_colon' => __('Parent Item:', 'text_domain'),
'new_item_name' => __( 'Nom de la nouvelle Thématique' ), 'new_item_name' => __('New Item Name', 'text_domain'),
'menu_name' => __( 'Thématiques' ), 'add_new_item' => __('Add New Item', 'text_domain'),
), 'edit_item' => __('Edit Item', 'text_domain'),
// Control the slugs used for this taxonomy 'update_item' => __('Update Item', 'text_domain'),
'rewrite' => array( 'view_item' => __('View Item', 'text_domain'),
'slug' => 'thematiques', // This controls the base slug that will display before each term 'separate_items_with_commas' => __('Separate items with commas', 'text_domain'),
// 'with_front' => false, // Don't display the category base before "/locations/" 'add_or_remove_items' => __('Add or remove items', 'text_domain'),
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/" 'choose_from_most_used' => __('Choose from the most used', 'text_domain'),
), 'popular_items' => __('Popular Items', 'text_domain'),
)); 'search_items' => __('Search Items', 'text_domain'),
'not_found' => __('Not Found', 'text_domain'),
'no_terms' => __('No items', 'text_domain'),
'items_list' => __('Items list', 'text_domain'),
'items_list_navigation' => __('Items list navigation', 'text_domain'),
);
$args = array(
'show_in_rest' => true,
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'meta_box_cb' => true,
);
register_taxonomy('taxonomy', array('articles', 'revues'), $args);
} }
add_action( 'init', 'add_custom_taxonomies', 0 ); // add_action('init', 'custom_taxonomy', 0);