Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Products

Products

// Register Custom Post Type
function products_post_type() {

	$labels = array(
		'name'                  => _x( 'Products', 'Post Type General Name', 'magic-lite' ),
		'singular_name'         => _x( 'Product', 'Post Type Singular Name', 'magic-lite' ),
		'menu_name'             => __( 'Products', 'magic-lite' ),
		'name_admin_bar'        => __( 'Product', 'magic-lite' ),
		'archives'              => __( 'Product Archives', 'magic-lite' ),
		'attributes'            => __( 'Product Attributes', 'magic-lite' ),
		'parent_item_colon'     => __( 'Parent Product:', 'magic-lite' ),
		'all_items'             => __( 'All Products', 'magic-lite' ),
		'add_new_item'          => __( 'Add New Product', 'magic-lite' ),
		'add_new'               => __( 'New Product', 'magic-lite' ),
		'new_item'              => __( 'New Product', 'magic-lite' ),
		'edit_item'             => __( 'Edit Product', 'magic-lite' ),
		'update_item'           => __( 'Update Product', 'magic-lite' ),
		'view_item'             => __( 'View Product', 'magic-lite' ),
		'view_items'            => __( 'View Products', 'magic-lite' ),
		'search_items'          => __( 'Search products', 'magic-lite' ),
		'not_found'             => __( 'No products found', 'magic-lite' ),
		'not_found_in_trash'    => __( 'No products found in Trash', 'magic-lite' ),
		'featured_image'        => __( 'Featured Image', 'magic-lite' ),
		'set_featured_image'    => __( 'Set featured image', 'magic-lite' ),
		'remove_featured_image' => __( 'Remove featured image', 'magic-lite' ),
		'use_featured_image'    => __( 'Use as featured image', 'magic-lite' ),
		'insert_into_item'      => __( 'Insert into Product', 'magic-lite' ),
		'uploaded_to_this_item' => __( 'Uploaded to this Product', 'magic-lite' ),
		'items_list'            => __( 'Products list', 'magic-lite' ),
		'items_list_navigation' => __( 'Products list navigation', 'magic-lite' ),
		'filter_items_list'     => __( 'Filter product list', 'magic-lite' ),
	);
	$rewrite = array(
		'slug'                  => 'product',
		'with_front'            => true,
		'pages'                 => true,
		'feeds'                 => true,
	);
	$args = array(
		'label'                 => __( 'Product', 'magic-lite' ),
		'description'           => __( 'Product information pages.', 'magic-lite' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields' ),
		'taxonomies'            => array( 'product_category' ),
		'hierarchical'          => false,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'menu_icon'             => 'dashicons-cart',
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => '%taxonomy_name%',
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
		'rewrite'               => $rewrite,
		'capability_type'       => 'page',
		'show_in_rest'          => true,
	);
	register_post_type( 'product', $args );

}
add_action( 'init', 'products_post_type', 0 );