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.
All-new Echo (2nd Gen) has a new speaker, new design, and is available in a range of styles including fabrics and wood veneers. Echo connects to Alexa to play music, make calls, set music alarms and timers, ask questions, control smart home devices, and more—instantly.
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.