How to Create Custom Post type in WordPress

How to Create Custom Post type in WordPress

What is Post Type in WordPress

WordPress can display many types of content. In wordpress we create “Posts, Pages”, it is also a post type called “post, page” respectively. There are some default post types in wordpress, these are

  • Post (Post Type: ‘post’)
  • Page (Post Type: ‘page’)
  • Attachment (Post Type: ‘attachment’)
  • Revision (Post Type: ‘revision’)
  • Navigation menu (Post Type: ‘nav_menu_item’)

What is Custom Post Type

These are the new post type that you can create using register_post_type() function in wordpress. Call this function using wordpress hook, good hook to call this function is init hook.

Below is an example to create “Product” post type using register_post_type() function.

How to Create Custom Post type in WordPress

After integrating this code in your themes functions.php, you will see a menu entry of your custom post type in your wordpress admin.

You should be able to add posts, view the post list in the admin and also visit the published posts on the website.

Note: After adding CPT in your wordpress admin you need to update your permalinks.

I’m a web developer / PHP programmer. I am also working on custom plugin development of wordpress.