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 900k 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”. Since we use the plugin in our site, you can view the live post example and category archive.
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/.
Points to Remember
- 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.
- All created post types and taxonomies can be viewed under “Registered Types/Taxes” menu.
- Deleting the custom post type plugin will not delete the content you created. It will only delete the post type names and menu items.
- You can also import / export post types / taxonomies and get the complete code under “Tools” menu.
- At any time, you can convert the custom post type content to regular post or page as you need.
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.
Problems to Expect with Custom Post Type
Though it is an easy way to add sub-sections to your site using custom post types, be aware of the following problems:
- Most commercial themes do not support custom posts. This means, you will not see theme elements like breadcrumbs, sidebar, post meta data, etc.
- Similarly, page builder and block plugins may not support custom posts.
- Caching plugins will create problems when you deal with CSS related optimizations like removing unused CSS, generating critical CSS or combining CSS files.
Therefore, we do not recommend creating custom post types unless you really need a different post style in the same site.