WordPress is a robust CMS ( Content management system ). By default, WordPress comes with post and page as the main content but you can create custom post type in WordPress to add your content.
Sometimes you may need to create custom post type in WordPress to add content like the portfolio, testimonials, course, events, etc which is not possible in post and page. You can create custom posts in WordPress either manually or by using some plugins. In this blog, I will show you how to create the custom post using a plugin.
Creating Custom Post type using Custom Post Type UI Plugin
This is the easiest way to create a custom post in your website, especially for beginners.
First, install & activate the CPT UI plugin upon activation it will add a new menu in dashboard called CPT UI
How to add custom post type?
Goto CPT UI > Click on Add/Edit Post types > Click on the tab Add new Post Type ( To create new post type ).
Now first enter your Post type slug. The slug is the user-friendly and URL valid name of a post ( ex: http://yourdomain.com/slug/post_title ). Your slug should contain only alphanumeric characters and underscores, you cannot use white space in your slug.
Enter Plural Label of your Custom Post Type ( Ex: Recipies, Movies, Portfolios etc ). Similarly, enter the singular label of custom post type in the next field.
There are some advance label options ( Description, menu name, All items etc ) and settings for more customization of your custom post type.
Now select the Post Editor features which you want in the backend while Editing/Adding your Custom Posts. By default Title, Editor and featured image is selected but if you want all features at the backend of your custom post check all the boxes except None.
You can also add available/registered taxonomies ( categories, tags, etc ) in custom post type as shown in below figure.
Note: Except WP core Taxonomies other displayed Taxonomies ( Portfolio, skills, groups etc ) will be changed according to the theme you are using
If you don’t want to use available taxonomies and need to create a new one then you can create new taxonomies using the same plugin. So let’s see how we can create new taxonomies.
How to create new taxonomies?
Goto CPT UI > Click on Add/Edit Taxonomies ( To create new Taxonomy or edit existing Taxonomies ).
All steps are same as that of custom post type,
Firstly enter your Taxonomy slug. slug should contain only alphanumeric characters and underscores, you cannot use white space in your slug.
Enter Plural Label of your Taxonomy ( Ex: Chefs, Types etc ). Similarly, enter the singular label of Taxonomy in the next field.
Now attach taxonomy with your desired Post Type from ” Attach to post type ” section. Here you have to select at least one post type either from registered post types or the custom post types which you have made.
There are some advance label options ( Description, menu name, All items etc ) and settings for more customization of Taxonomy.
Now click on save to create Taxonomy.
Displaying of your custom post type
WordPress come with default template files by which you can display your custom post type. let’s see the different methods to display your custom post type.
Displaying using archive template ( archive.php file )
if you are using SEO Friendly permalinks your custom post type archive page URL will be
If you are not using SEO friendly permalink your custom post type URL will be like this
Replace domain.com with your domain name and custom_post_type_name with your Custom post type name and enter URL. Now you will see archive page of your custom post type.
If you want a specific template for your custom post then create a new file in theme directory with name archive-cpt_name.php.
Replace cpt_name with your custom post type name and copy the code of archive.php in your new template file. Now make customization/modifications in the file according to your needs.
Displaying Single post using ( single.php file )
Similarly, the single post of your custom post type is displayed using template file single.php.
If you want to make any customization/modifications in template make a new file with name single-cpt_name.php. replace cpt_name with your custom post type name and copy the code of single.php in your new template file single-cpt_name.php and modify the code according to your needs.
Hope this article helped you to create and display custom post type.