how to create custom post types in WordPress

How to create custom post types in WordPress?

The way information is displayed on your website makes a massive difference to its presentation and your user’s experience. That is why you should know how to create custom post types in WordPress.

Among the reasons why WordPress is so versatile and flexible as a CMS for marketing, is having the ability to deal with multiple post types. Depending on the kind of content you publish on your site, you might need to work with various different formats that change the look and feel of your articles.

Custom post types in WordPress are used to accommodate different kinds of content you might want to publish on your site.

For instance, a product page is a type of post that might fit well into a WordPress ecommerce, with a ready-made structure that includes a name, picture, technical details, and others.

By default, WordPress comes with five post types: post, page, attachment, revision, and nav menu. Those are supposed to fit the needs of most users, but you can also create your own through third-party WordPress plugins, or even manually. This will allow you to extend the functionality of your WordPress panel.

This is what you will learn in this article:

In which situations would I need custom post types?

The term post type is used by WordPress to refer to a template or predefined structure that is called when creating content with the platform. Post types are stored in your WordPress database under the post_type column.

When someone publishes a new article on an informational blog, they are actually using the post type. When one adds a contact section, this usually is a page type.

Think of a WordPress blog about movies where the authors publish reviews periodically. This could be done through a regular post type, but its functionality can be further improved by working with a custom review post type.

Imagine it already comes with a spot for the movie poster, the number of stars, and even a space for the cast and crew information.

There are some situations in which you might want to use a post type that is not offered by default in WordPress. Here are a handful of possible scenarios:

  • your WordPress site has specific kinds of content that does not fit into the default post types;
  • your published content needs extra fields other than the defaults, such as title, content, and tags;
  • you need to be able to publish content that is not necessarily in chronological order, such as a glossary or catalog;
  • you want to control how a specific kind of post is displayed, preferentially in a different way from regular ones;
  • you need additional ways to separate your content other than categories and tags.

How to create custom post types with a plugin?

Custom post types in WordPress can be created with specific plugins. These usually extend the features available on your admin panel, giving you the ability to perform tasks not originally supported.

Using a plugin is the easiest way to create custom post types in WordPress. That is because most of the back-end work is done automatically, without requiring technical knowledge on your part.

Below, you will find a step-by-step guide on how to create custom post types in WordPress using the Custom Post Type UI plugin.

1. Download and install Custom Post Type UI

Custom Post Type UI is a simple plugin that gives you access to an interface that facilitates the creation and editing of custom post types on your WordPress panel.

Just search for it by going to Plugins and download the latest version. After that is done, click Activate. This will make a new menu appear on your left sidebar named CPT UI.

2. Add a new custom post type to CPT UI

After installing CPT UI, navigate to its menu on the left sidebar and pick Add/Edit Post Types.

The first piece of information you need to fill out is the slug, which is how the custom post type will be displayed on your site’s URL. As usual, it can only contain letters and numbers, without spaces.

Below, you need to offer plural and singular names that define that custom post type. For instance, in case you are creating a movie review post type like in the example above, then the plural would be “Reviews” and the singular would be “Review”.

After you do that, clicking on “Populate additional labels based on chosen labels” will automatically fill out the rest of the form with data from the plural and singular nouns.

All of those entries might be used on your layout depending on how post types are displayed by your template.

3. Configure custom post type settings

In this section, you can set up different attributes for your new custom post type.

For instance, you can define this post type as publicly viewable or not. This is also where you should set whether it appears on navigation menus and search results.

Further below, you can use checkboxes to select the features someone should have when creating a post that fits this type.

For instance, you can create a post type that only has a title, for a tweet-like piece of content, for example. Alternatively, you can remove default fields and leave only the ones you absolutely need.

4. Finish creating your post type and test it

After configuring your new custom post type, make sure to save it. You can edit it later in case you need to make further changes.

Make sure to test it. Create a default post and select the newly created custom type and see if it behaves as you intended.

Lastly, take care to check if it is displayed correctly on your current WordPress theme.

How to create custom post types manually?

In case you want more freedom when working with custom post types in WordPress, you can choose to do the process manually. Not depending on a plugin for that also safeguards your definitions in case it is disabled or deleted.

This is a more complex approach that is intended for those who have web development knowledge. The advantage is being able to create custom post types without the need of installing third-party plugins, which is better for your WordPress security.

Here is the step-by-step process on how to create custom post types in WordPress manually.

Secure your page with Stage!

1. Add the code to functions.php

The functions.php file on your WordPress installation governs several features of your site. In order to work with custom post types in WordPress, you need to enable it first by editing this file.

You can do that with any text editing software such as Notepad. Below you can find an example of a filled-out template that adds a movie review post type:

function create_posttype() {
  register_post_type( 'review',
  // CPT Options
    array(
      'labels' => array(
        'name' => __( 'Reviews' ),
        'singular_name' => __( 'Review' )
      ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => array('slug' => 'review'),
      'show_in_rest' => true,
    )
  );
}
add_action( 'init', 'create_posttype' );

2. Edit the variable parameters

The code you added to functions.php can be edited further to specify the custom post type’s settings.

With it, you can define the custom post type’s visibility; whether it appears on the archive, its slug name, and even disable the block editor support.

You can extend this code further by adding extra labels that define how the custom post type appears on your WordPress theme. Make sure to check the documentation related to it to know how to approach this.

3. Testing the custom post type

After making the necessary changes to the functions.php file and uploading the updated version to your WordPress hosting file system, you should test your addition.

By the way, there is no need to enable your custom post type manually, since WordPress has native support for it as long as it is properly coded into the functions.php file.

Proceed to create a default post and select the custom type you created. Check if it behaves as you intended.

How to display custom post types on your WordPress site?

After creating your custom post types in WordPress, you need to make sure they are displayed correctly on your website or blog.

It does not matter whether you created your custom post type with a plugin or manually, as the process is the same. Displaying the content is a question of adding it to navigation menus, the archive, and other entries.

Head to Appearance and choose Menus. There, add a new custom link and use the website URL with the slug you defined for your custom post type. Make sure to test it beforehand.

When you do that, WordPress will use the default archive page to display your content. It works just like any other archive, except it only shows the posts set with that newly created type.

By editing your template, you can also create alternate ways to display your archive when working with specific post types. This is ideal when they are vastly different from traditional types of posts.

WordPress is a highly flexible tool for online publishing. No matter what you want to put on the web, it has extensive features that allow you to succeed. By leveraging custom post types in WordPress, you are able to personalize how information is published and displayed on your website.

How about further extending your knowledge on this powerful platform? Download our free guide on WordPress for corporate blogs and learn more!

WordPress Guide for Corporate Blogs - Promotional Banner

Want to get more content like this for free?

Sign up to receive our content by email.

Email registered successfully
Oops! Invalid email, please check if the email is correct.

Share your thoughts

Your email address will not be published.