Prevent new terms being added to a custom taxonomy

Sometimes, you create some custom taxonomies using register_taxonomy or CPT UI… and want disable add new taxonomy’s term (before handling to client…)

This snippet will allow you disable creating new term

add_action( 'pre_insert_term', function ( $term, $taxonomy )
{
    return ( 'your_taxonomy_name' === $taxonomy )
        ? new WP_Error( 'term_addition_blocked', __( 'You cannot add new terms to this taxonomy' ) )
        : $term;
}, 0, 2 );

 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments