How to Create Custom Post Type In WordPress Without Plugin
Welcome to our comprehensive beginner’s guide to Custom Post Type In WordPress! In this tutorial, we will walk you through everything you need to know about creating and utilizing custom post types in WordPress. Whether you’re a beginner looking to expand your WordPress knowledge or a seasoned developer seeking to enhance your website’s functionality, this tutorial is for you. We’ll cover the basics of Custom Post Type In WordPress, step-by-step instructions for creating them, and offer tips and best practices along the way. Join us and unlock the power of Custom Post Type In WordPress!
// Product Custom Post Type function product_init() { // set up product labels $labels = array( 'name' => 'Products', 'singular_name' => 'Product', 'add_new' => 'Add New Product', 'add_new_item' => 'Add New Product', 'edit_item' => 'Edit Product', 'new_item' => 'New Product', 'all_items' => 'All Products', 'view_item' => 'View Product', 'search_items' => 'Search Products', 'not_found' => 'No Products Found', 'not_found_in_trash' => 'No Products found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Products', );
// register post type
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘has_archive’ => true,
‘show_ui’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘rewrite’ => array(‘slug’ => ‘product’),
‘query_var’ => true,
‘menu_icon’ => ‘dashicons-randomize’,
‘supports’ => array(
‘title’,
‘editor’,
‘excerpt’,
‘trackbacks’,
‘custom-fields’,
‘comments’,
‘revisions’,
‘thumbnail’,
‘author’,
‘page-attributes’
)
);
register_post_type( ‘product’, $args );
// register taxonomy
register_taxonomy(‘product_category’, ‘product’, array(‘hierarchical’ => true, ‘label’ => ‘Category’, ‘query_var’ => true, ‘rewrite’ => array( ‘slug’ => ‘product-category’ )));
}
add_action( ‘init’, ‘product_init’ );
Fiverr
Programming & Tech
Hafiz Umar Bhatti
Looking for a WordPress expert? With over 5 years of experience, Let’s bring your website dreams to life with fluent communication and top-notch quality.