Sometimes, when using a custom post type in your plugins (or themes), it is desirable to add the already-registered taxonomies (Post Tags and Categories by default) to your custom object type. This quick code snippet will show you how to do that.
This is a quick tip. Check out more Quick Tips
Using the register_taxonomy_for_object_type(), we will specify a taxonomy and an object type, then hook our function into an init hook.
1 2 3 4 | add_action('init','add_categories_to_cpt'); function add_categories_to_cpt(){ register_taxonomy_for_object_type('category', 'post_type_name'); } |
This will work fine, but sometimes the init hook won’t always work. If you your custom post type is created in a plugin, you may need to use the plugins_loaded hook instead, which fires after all plugins have been loaded. Like this:
1 2 3 4 | add_action('plugins_loaded','add_categories_to_cpt'); function add_categories_to_cpt(){ register_taxonomy_for_object_type('category', 'post_type_name'); } |
Enjoy!

I want to have Post Tags added to the Custom Post Types created. Which file do I need to add the code to? Is there another way to have the Post Tages enabled?
Just use this:
register_taxonomy_for_object_type('post_tag', 'post_type_name');Put it in your functions.php, or plugin file if you’re writing a plugin.
Hmm.. don’t get it … I’m using the Easy Content Types plugin and want to have the post tags available in the created Content Types. Which functions.php do you mean, from the theme, wordpress or …
@Jeroen – Ah, you should have said so
There’s a section in the documentation that says how to do it. Go to the help page and look in the taxonomy section.
In the future when asking about a plugin, please comment on the plugin post.
Should have done that first.. missed the part in the docs. Got it working now! Thanks!
Pippin,
I’ve been trying to add the categories to your sugar calendar plugin using this code, but nothing seems to happen. I’ve tried it both ways. Here is the code I’ve tried:
‘
//Register categories with events
add_action(‘init’,'add_categories_to_cpt’);
function add_categories_to_cpt(){
register_taxonomy_for_object_type(‘category’, ‘sc_event’);
}
‘
and
‘
//Register categories with events
add_action(‘plugins_loaded’,'add_categories_to_cpt’);
function add_categories_to_cpt(){
register_taxonomy_for_object_type(‘category’, ‘sc_event’);
}
‘
and yes, I put these in the funtions file.
Sean in SF
Change
to
Thanks for the tips! But how can I tell if I had successfully add a custom taxonomy to a custom post type with this method? Is there any way to check the taxonomy’s relationship with the post type?
That’s a completely different topic than this post.