Over the years, WordPress has become much more than just a blogging content management system (CMS). One of the best things about WordPress is its ability to expand. It went from being a mere blogging platform, to a CMS that is capable of creating all kinds of complex websites. WordPress has a feature that allows further customization when it comes to content types, such as posts and pages. This feature is known as Custom Post Types.
What are Custom Post Types in WordPress?
A WordPress Post Type is basically a type of content, for example, a blog post is a post type, a page is another post type. On a fresh install, WordPress comes with 5 default post types, they are:
- Post (Post Type: ‘post’)
- Page (Post Type: ‘page’)
- Attachment (Post Type: ‘attachment’)
- Revision (Post Type: ‘revision’)
- Navigation Menu (Post Type: ‘nav_menu_item’)
Learn more about WordPress Custom Post Types from the WordPress Codex
Creating Custom Post Types
WordPress allows you to create more than these default post types. Let’s say we want a portfolio section in our website, we can create a new post type and call it Portfolio. There are two main ways to create a custom post type; through code or through a plugin.
Creating a Custom Post Type through Code
You can create a custom post type by adding some code to the
functions.php file in your WordPress theme folder. Although this gives you more control over the code, it is not the most efficient way. Because the
functions.php file is inside your theme folder, the post type you create will disappear when you use another theme! You can, however, create your own plugin.
Learn how to Create a Custom Post Type Plugin
Creating a Custom Post Type through a Plugin
The easier, more efficient way to create a custom post type in WordPress is using a plugin. One of the best custom post types plugins out there is CPT UI. Let’s go through the steps for creating a custom post type for our favorite books.
1. Install The CPT UI Plugin
First thing we need to do is add and activate the Custom Post Type UI plugin on our WordPress admin area. Go to Plugins > Add New, then type Custom Post Type UI in the search bar, and hit Enter.
The plugin we’re looking for is the first result on the left. Click on Install.
After the installation is done, click on Activate Plugin.
2. Add/Edit Post Types
After you’ve activated the plugin, you should have a new option, CPT UI, in your WordPress admin menu on the left. Click on CPT UI > Add/Edit Post Types.
Now, fill in the information for our custom post type. In this case, we will create a ‘book’ custom post type.
The default settings should be fine as they are, however, we should focus on a couple of settings. The first one is Has Archive > True. This setting will make sure that our custom post type has an archive, so if we go to http://ourwebsite.com/books it will display all our book posts.
The second set of settings we want to look at is the Menu Position, this is where the post type will appear on your Admin Area’s sidebar. Will will give it a position of 6, so that it displays under posts.
The third important setting is the Supports options. These options allow you to choose what fields your post type will support. For books, we will choose a Title, an Editor, an Excerpt and a Featured Image.
Finally, scroll back up, and click on Add Post Type.
3. Add Content to Your Post Type
You might need to refresh the page, but our new post type should appear in the menu right below Posts. Let’s add a new book. Click on Books > Add New.
Now, fill in some content, and click on Publish.
Finally, if we click on the permalink of our new book post, it should take us to the book on our website. Depending on your theme, this could look different.
Further Help on Custom Post Types
Now that you know how to create a custom post type for your WordPress site, you can look through some of these helpful links to further customize the look and feel of your WordPress custom post types.
- Post Type Templates – WordPress Codex
- How to Create a Custom Post Type Archive Page in WordPress – WP Beginner
- Create Custom Single Post Templates for Specific Posts or Sections in WordPress – WP Beginner