Add categories and tags support to custom post types in WordPress

Adding a custom post type in WordPress is pretty easy and while it can be done and managed via external plugins, it’s pretty easy to do it by adding a little code in the functions.php file of your theme. All we need to do is take advantage of the “register_post_type” method that’s provided by wp. You can see more details and all the params on the Codex.

Here is a simple example that creates a custom post type named “project”:

By default, this new custom post type doesn’t has the ability to use taxonomies (categories, tags, or any other custom taxonomies you might need), but that can be easily added. Simply add ‘taxonomies’ => array(‘category’, ‘post_tag’) to the $args variable then initialize the new taxonomies. The code will look like so:

If anyone knows an easier way (without using a plugin) of achieving this, please use the comments section below!

Leave a Reply

Your email address will not be published. Required fields are marked *