A Custom post type is a powerful way to extend the functionality of your WordPress site. Instead of being limited to the default Pages and Posts, you are able to add and customize any kind of post type you would like. You can do this by adding some simple code to the
functions.php file of your WordPress theme.
Quick and Simple Way to Add a Custom Post Type
For example, let’s say you want to feature cars on your website and you want to setup a custom post type for this. All you need to do is add in this code to your
functions.php file to make it work:
That’s it! You’re now ready to use your new custom post type. If you return to your WordPress Dashboard, you’ll notice that “Cars” now appears in your admin menu.
A Bit More Functionality
While the above code will get the job done, there are plenty of times where you may need to customize and extend the functionality of your post type a bit more. For example, you may want your new “Cars” post type to be organized by categories or tags. In order to accomplish this, you’ll need to write a bit more code, but it’s still pretty straightforward.
- Easy and simple to use – plug it in and go
- Fast file transfers with SuperSpeed USB 3.0
- Compatible with USB 3.0 and USB 2.0
- Powered by USB port
- Drag and drop file saving for Windows, right out of the box.
In order to have all the options for a post type open to you, drop this code into your
That may seem like a lot of code, but most of these are straightforward and simply tell WordPress how to display certain things on the admin side. You’ll notice that the categories and tags for your post type have been enabled on this line
'taxonomies' => array('category', 'post_tag').
Some other handy things to know are, for example, if you want to have an archive of your posts, you need to be certain that the archive option is set to “true” like this:
'has_archive' => true. To add or remove certain editing capabilities such as the text editor or post title, you can manipulate the
'supports' parameters. Lastly, if you want your custom post type to have a unique menu icon, you can change this by altering this line:
'menu_icon' => 'dashicons-admin-post'. A list of icons you can use are available here.
Note: After setting up a custom post type, you may need to reset your permalinks through your WordPress admin settings.