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.
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
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”.
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.
The details provided under this section determine the behavior of the post type.
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.
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:
How it Will Look?
After changing all your settings, you will see a menu named “Demos” added with sub menus as shown below:
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/.
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.