Is there a way to ‘Lock’ a Taxonomy?

The question:

I was wondering if there was a way to prevent the addition of new categories into a taxonomy, essentially ‘locking’ the taxonomy.

I’m programatically registering a taxonomy and filling it with terms via functions.php and would like it so you cannot add anymore into it.

The Vision, REALIZED…

Heres how my solution ended up looking, and it works great! THANKS to everyone who helped. Upvotes all over the place up in your face!

// some stuff happens before this...
    $labels = array(
        'name' => _x( 'Attendees', 'taxonomy general name' ),
        'singular_name' => _x( 'Attendee', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Attendees' ),
        'all_items' => __( 'All Attendees' ),
        'edit_item' => __( 'Edit Attendee' ), 
        'update_item' => __( 'Update Attendee' ),
        'add_new_item' => __( 'Add New Attendee' ),
        'new_item_name' => __( 'New Attendee Name' ),
        'menu_name' => __( 'Attendees' )
    $rewrite = array(
        'slug' => 'attendee'
    $capabilities = array(
        'manage_terms' => 'nobody',
        'edit_terms' => 'nobody',
        'delete_terms' => 'nobody',
        'assign_terms' => 'nobody'
    $args = array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => 'attendee',
        'rewrite' => $rewrite,
        'capabilities' => $capabilities
    register_taxonomy('attendees', 'meetings', $args);
add_action( 'init', 'todo_create_taxonomies', 1);
function todo_register_attendees() {
    $users = get_users();
    foreach ( $users as $user ) {
        wp_insert_term( $user->display_name, 'attendees', array('description'=> $user->display_name, 'slug' => $user->user_nicename) );
        $lockdown[] = $user->user_nicename;
    $terms = get_terms('attendees', array('get' => 'all') );
    foreach ($terms as $term) {
        if ( !in_array($term->slug, $lockdown) ) {
            wp_delete_term( $term->term_id, 'attendees' );
            $message = new WP_Error('force_terms', __('Only Registered Users can be Attendees, ' . $term->name . ' has been deleted.'));
            if ( is_wp_error($message) ) { ?>
                <div id="aphid-error-<?php echo $message->get_error_code(); ?>" class="error aphid-error"> 
                    <p><strong><?php echo $message->get_error_message(); ?></strong></p>
            <?php }
add_action( 'admin_notices', 'todo_register_attendees' );

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Categories, Tags & Taxonomies

First i want to make this one clear: Everything is a Taxonomy. Tags is a non-hierarchical, Categories a hierarchical and both are built-in taxonomies. Same goes for eg. post formats (aside, chat, etc.). It’s the same concept as with post-types (post, page, attachment, nav_menu_item, etc. are all just built in post types).

Everything inside one of those Taxonomies is a Term. For eg. (inside post formats) “aside”, “quote”, “audio”.

Codex Links

The Concept

The following is for your functions.php file. This triggers on every page request. You could improve it – using the Transients API – to trigger on given timestamps (eg. twice daily, hourly, etc.).

function wpse14350_cleanup_taxonomy_terms()
    // Define your terms inside this array
    $predefined_terms = array(
         'term A'
        ,'term B'
        ,'term C'
    // Name your taxonomy here
    $predefined_taxonomy = 'category';

    $all_terms_inside_tax = get_terms( 
             'hide_empty'   => false
            ,'taxonomy'     => $predefined_taxonomy

    foreach ( $all_terms_inside_tax as $term )
        if ( ! in_array( $term->name, $predefined_terms ) )
            wp_delete_term( $term->term_id, $predefined_taxonomy );
add_action( 'init', 'wpse14350_cleanup_taxonomy_terms' );

Method 2

If you’re adding terms into the taxonomy independantly and you want to hide the UI, why not simply use two of register_taxonomy‘s supported arguments.

(array) (optional) An
array of the capabilities for this

Default: None

‘manage_terms’ – ‘manage_categories’
‘edit_terms’ – ‘manage_categories’
‘delete_terms’ – ‘manage_categories’
‘assign_terms’ – ‘edit_posts’

(boolean) (optional) Whether to generate a default UI for
managing this taxonomy.

Default: if not set, defaults to value of public argument

Set the capabilities to some nonexistent capabilities and you’ll essentially prevent users from being able to modify, create or delete them. If you need to be able to assign them to posts the traditional way(ie. via the post editor), simply use a real capability for the assign_terms value.


$args = array(


    'capabilities' => array(
        'manage_terms' => 'foobar',
        'edit_terms'   => 'foobar',
        'delete_terms' => 'foobar',
        'assign_terms' => 'foobar' // <-- change this one to a desired cap if you need to be able to assign them(you could use manage_options for admins only)

Set show_ui to false and you’ll prevent any menu items being shown for the taxonomy.

Hope that helps…

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment