Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Create a Custom Post Type in WordPress

This guide shows you how to add your own kind of content, such as "Books" or "Recipes", to WordPress.

WordPress2 min read16 steps

What is a custom post type?

WordPress comes with built-in content types. The two you know best are Posts and Pages. A custom post type is a new content type that you make yourself. Think of a school bag. One pocket holds pens and another holds books. A custom post type is a new pocket for one kind of content.

You can make one in two ways. A plugin is easier. Code gives you more control.

Method 1: Use a plugin

A plugin is a small add-on program for WordPress. Many free plugins can create post types. Custom Post Type UI is a popular one.

  1. Log in to your WordPress dashboard. The dashboard is your control room.
  2. Click Plugins, then Add New.
  3. Search for "Custom Post Type UI".
  4. Click Install Now, then Activate.
  5. Click the new CPT UI menu, then Add/Edit Post Types.
  6. Type a short name in Post Type Slug. Use small letters only, such as book.
  7. Type the plural name, such as "Books", and the single name, such as "Book".
  8. Click Add Post Type.

A new "Books" item now shows in your left menu. Click it to add entries.

Method 2: Use code

Warning: A small mistake in code can break your site. Take a backup first. Use a child theme or a small plugin. Do not edit a theme that gets updates.

A child theme is a safe copy layer on top of your main theme. Your changes stay when the main theme updates.

  1. Open your child theme's functions.php file. You can use the File Manager in your hosting control panel.
  2. Add this code at the bottom of the file.
function hv_register_book_type() {
    register_post_type('book', array(
        'labels' => array(
            'name' => 'Books',
            'singular_name' => 'Book'
        ),
        'public' => true,
        'has_archive' => true,
        'supports' => array('title', 'editor', 'thumbnail'),
        'show_in_rest' => true
    ));
}
add_action('init', 'hv_register_book_type');

This code tells WordPress to create a public "Books" type with a title, a text editor and a picture box.

  1. Save the file.
  2. In the dashboard, click Settings, then Permalinks, then Save Changes. This refreshes your page links.

Check that it works

  1. Click Books in the left menu.
  2. Click Add New.
  3. Write a title and some text.
  4. Click Publish, then view the entry.
Tip: If the entry shows a "Not Found" page, save your Permalinks again.

Quick recap

  • A custom post type is a new kind of content in WordPress.
  • A plugin is the easiest way to make one.
  • Code in a child theme gives more control. Back up first.
  • Save your Permalinks after you add a new type.