Modifying Custom Taxonomy Forms in WordPress

Today, I was working on a client project and needed to add a little snippet underneath a hierarchical taxonomy form that was registered on a custom post type. Unfortunately, after spending about ten minutes digging through core and googling, I couldn’t find an action hook to use. Luckily, after tracing the output a little further back, I found what I was looking for.

When registering a custom taxonomy, one of the oft forgotten arguments is meta_box_cb, or the callback function used to render the meta box in the admin edit screen. Tracing this back a little further, the default value is set in wp-includes/taxonomy.php on Line 454. Using one of those default functions within our custom callback, we can essentially add as much code before or after the default taxonomy form.

register_taxonomy( 'acme_custom_taxonomy', array( 'my_cpt', 'post' ), array(
'meta_box_cb' => 'acme_metabox_cb',
) );
function acme_metabox_cb( $post, $box ){
// Render the default hierarchical meta box form
post_categories_meta_box( $post, $box );
// Add all of our new stuff!
echo "<p>This will show up below the checkboxes that you are used to!</p>";

It’s that simple! If you need to add something to the non-hierarchical taxonomy form, simply swap out line 9 for the post_tags_meta_box() function instead.

Author: Daron

Professional WordPress enthusiast and developer with a recent interest in Laravel. When not doing WordPress, he enjoys Netflix and playing Nintendo. He is also available for freelance opportunities. Get in touch to hash out the details.

Leave a Reply

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