How to Create Custom Post Type in WordPress?

WordPress by default offers ten post formats like standard, gallery, link, video, audio, status, aside, chat, quote and image. Theme developers can use some or all these formats in the theme. Users can choose the post format when creating a new post using post meta box in the visual editor. Sometimes these post formats are not sufficient and you need additional format for showcasing your content. For example, you may want to showcase portfolio or demos and offer discount deals to user with custom format. This will also help to have custom XML Sitemap for that post format and allow you to customize the template as per your need.

In this article let us discuss how to create custom post type in WordPress using Custom Post Type UI plugin.

How to Create Custom Post Type in WordPress?

Install and activate the Custom Post Type UI plugin. This plugin has more than 400k active installs and allows users to easily create custom posts and taxonomies.

Custom Post Type UI WordPress Plugin
Custom Post Type UI WordPress Plugin

Once activated the plugin will add a menu item named “CPT UI”. Basically you need to create a post type and a taxonomy to group your posts. In this article let us create a post format “Demos” and a taxonomy “Demo Categories”.

Creating Custom Posts

Navigate to “CPT UI > Add/Edit Post Types” and click on the tab “Add New Post Type”. You will see huge list of options categorized into three groups:

  • Basic settings
  • Additional labels
  • Settings
Related:  How to Change Font Styles in Weebly Site?
Basic Settings

Under this section enter the slug, singular and plural label for your custom post type. Remember the slug is very important and you can’t change it later. Also you can’t create a post types with subdomain names. For example, if you have a subdomain “demos.webnots.com” then you should not create custom post type with the name “Demos”.

CPT UI Basic Settings
CPT UI Basic Settings
Additional Labels

Here you can provide naming for various sections of your custom post type. For example, you can change the name on the menu and the default phrases like featured image. Generally the details provided under this section are not important.

Additional Labels Section of CPT UI Plugin
Additional Labels Section of CPT UI Plugin
Settings

The details provided under this section determine the behavior of the post type.

Settings Section of CPT UI Plugin
Settings Section of CPT UI Plugin

Following are some of the important settings you should setup:

  • Has archive – the default value is false, you should select true if you want to have archive page for your posts. In our example the archive page can be accessed with the URL “webnots.com/demos/”.
  • Exclude From Search – setting true will disable showing the custom post types in default WordPress search results. You can set this as true especially you don’t use excerpt and have codes at start of the posts instead of text.
  • Menu Icon – upload the menu icon to be shown in the admin panel.
  • Supports – choose the post editor features you want to have on the visual editor. For example, you can uncheck “Comments” so that comment section is disabled.
  • Built-in Taxonomies – choose the taxonomies to be supported for the custom post type. You can create a custom taxonomy assign it here later.
Related:  Using Weebly Education Version for Teachers and Students

Create Custom Taxonomy

For our example, we will create a custom taxonomy called “Demo Categories”. Navigate to “CPT UI > Add/Edit Taxonomies > Add New Taxonomy” and provide the details similar to post type. Ensure to select the custom post type “Demos” under “Basic Settings > Attach to Post Type” as shown below:

Creating Custom Taxonomy
Creating Custom Taxonomy

How it Will Look?

After changing all your settings, you will see a menu named “Demos” added with sub menus as shown below:

Viewing Menu of Custom Post Type
Viewing Menu of Custom Post Type

You can start creating custom post type / custom categories similar to normal posts / categories. The URL of the custom post type (when you use post title as permalinks) will be like “yoursite.com/custom-post-type/post-title/.

1. When you use Yoast SEO or any other Sitemap generation plugin, ensure to add the created custom post type and taxonomy in the XML Sitemap.

2. All created post types and taxonomies can be viewed under “Registered Types/Taxes” menu.

3. Deleting the custom post type will not delete the content you created. It will only delete the post type names and menu items.

4. You can also import / export post types / taxonomies and get the complete code under “Tools” menu.

Customizing Post Template

The plugin will only allow you to create custom post types and taxonomies. These custom posts will use the default theme’s templates. For example, the demos post will use “single.php” as post template which is the default post template used by themes. If you want to use custom template for demos, then create a new template called “single-demos.php” and upload it inside the theme folder (where “single.php” is available). You can then start customizing the “single-demos.php” file as per your need.

Recommended Articles:

Leave a Comment