How to Create Custom Content / Post Types in WordPress

wordpress-custom-post-type

Default Post Types in WordPress

By default, WordPress comes with two main post types.

  1. Post: Mainly used for creating blog posts.
  2. Page: Used for creating basic / standard pages like About, Contact etc.

Add new content / post type in WordPress

Let’s create a new post type Book.
Add below codes in functions.php file of your theme.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
 * Custom post type book.
 */

function book_post_type() {
register_post_type( 'book',
// options for book post type.
  array(
    'labels' => array(
     'name' => __( 'Book' ),
     'singular_name' => __( 'book' )
    ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array('slug' => 'book'),
    'show_in_rest' => true, // Add support for Gutenberg editor
    'supports' => array(
      'title',
      'editor',
      'excerpt',
      'comments',
      'thumbnail',
    )
  )
);
}
// Hooking up our function to theme setup
add_action( 'init', 'book_post_type' );

You can edit above codes and make custom changes to your new content type.

You can now see this new post type in your WordPress dashboard.
wordpress-add-custom-post-type

Using Plugin

If you want to create custom post types by just few clicks, you can use plugin. There are many WordPress plugins for creating new custom post type.


Hope this tutorial was helpful.
If you need help with custom post type in WordPress, Please leave a comment below and I will get back to you.

Related Posts

Leave a Reply

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