The code is in “functions.php”.
Here is my code:
function cpt_product() {
$labels = array(
'name' => 'Products',
'singular_name' => 'Products',
'menu_name' => 'Products',
'name_admin_bar' => 'Products',
'all_items' => 'All Products',
'add_new_item' => 'Add New Product',
'add_new' => 'Add New',
'new_item' => 'New Product',
'edit_item' => 'Edit Product',
'update_item' => 'Update Product',
'view_item' => 'View Product',
'view_items' => 'View Products',
'search_items' => 'Search Product',
);
$rewrite = array(
'slug' => 'product',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => 'Product',
'description' => 'Products',
'labels' => $labels,
'supports' => array( 'title', 'thumbnail' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-products',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => 'product',
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'product', $args );
}
add_action( 'init', 'cpt_product', 0 );