How to Create Custom Post Type In WordPress without Plugin

Play Video

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’ );

Picture of Hafiz Umar Bhatti

Hafiz Umar Bhatti

I am a full-time designer. I am ready to provide the best service possible. Furthermore, I am happy to serve you. Let’s get started! 🙂 I am an expert in Adobe Photoshop, Illustrator, XD, and InDesign. I also specialize in web design and development, including but not limited to. Creating WordPress websites from Scratch.
Open chat
Hello
Can we help you?