How to register custom post types in wordpress

Shortlink:

Hello, Today i will teach you how to register custom post type in your WordPress website, it’s simple work,

Open Your functions.php file in your current active theme then you can copy below codes and past in your functions.php file.

            add_action( 'after_setup_theme', 'create_post_type' );
function create_post_type() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'Testimonial' ),
'singular_name' => __( 'Testimonial' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Testimonial' ),
'edit_item' => __( 'Edit Testimonial' ),
'new_item' => __( 'New Testimonial' ),
'view_item' => __( 'View Testimonial' ),
'not_found' => __( 'Sorry, we couldn\'t find the Testimonial you are looking for.' )
),
'public' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'testimonial' ),
'supports' => array( 'title', 'editor', 'custom-fields' )
)
);
}

 

You can use action hook is ‘after_setup_theme‘ or ‘init‘ but now update code is ‘after_setup_theme

Functions Reference

Functions Reference

 

How to Query Custom post types with taxonomy or without taxonomy

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!




%d bloggers like this: