Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Created December 19, 2022 14:52
Show Gist options
  • Save thierrypigot/d999e026a04b0b26d2013f5c2437785e to your computer and use it in GitHub Desktop.
Save thierrypigot/d999e026a04b0b26d2013f5c2437785e to your computer and use it in GitHub Desktop.
<?php
// Déclaration de la fonction pour créer le Custom Post Type
function ma_fonction_cpt() {
// Définition des labels pour le CPT
$labels = array(
'name' => _x( 'Produits', 'Post Type General Name', 'mon_text_domain' ),
'singular_name' => _x( 'Produit', 'Post Type Singular Name', 'mon_text_domain' ),
'menu_name' => __( 'Produits', 'mon_text_domain' ),
'parent_item_colon' => __( 'Produit parent:', 'mon_text_domain' ),
'all_items' => __( 'Tous les produits', 'mon_text_domain' ),
'view_item' => __( 'Voir le produit', 'mon_text_domain' ),
'add_new_item' => __( 'Ajouter un nouveau produit', 'mon_text_domain' ),
'add_new' => __( 'Ajouter un produit', 'mon_text_domain' ),
'edit_item' => __( 'Modifier le produit', 'mon_text_domain' ),
'update_item' => __( 'Mettre à jour le produit', 'mon_text_domain' ),
'search_items' => __( 'Rechercher un produit', 'mon_text_domain' ),
'not_found' => __( 'Aucun produit trouvé', 'mon_text_domain' ),
'not_found_in_trash' => __( 'Aucun produit trouvé dans la corbeille', 'mon_text_domain' ),
);
// Configuration des paramètres du Custom Post Type
$args = array(
'label' => __( 'produit', 'mon_text_domain' ),
'description' => __( 'Tous les produits', 'mon_text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
// Enregistrement du type de publication
register_post_type( 'produit', $args );
}
// Hook pour l'enregistrement du CPT
add_action( 'init', 'ma_fonction_cpt', 0 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment