Skip to main content

How to Create Custom Content / Post Types in WordPress

Submitted by admin on Wed, 12/08/2021 - 13:17
Wordpress custom page 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.


/**
 * 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.

Category

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.