Can I turn off write-in tags/taxonomies?

One of the big problems my site staff has had with tags is the overwhelming number of similar or duplicate tags, due to the write-in ability.

I’m about to add new custom taxonomies to my site for them to use, but I’d like to avoid the problem we had with tags. I’m curious to know if I can turn off write-ins, so they can only be added manually through that taxonomy’s part of the admin area. It’s non-hierarchical, so they can still type in and the system will auto-complete and search for tags they might be looking for, which is great. I just don’t want them to be able to create new tags from the post screen.

Is this possible? I was looking at the Taxonomies and register_taxonomy() pages in the Codex, and thought maybe the “rewrite” function might be what I’m looking for, but I don’t think it is now.

1 Answer
1

Here is what I came up with, seems to work:

add_filter( 'pre_post_tags_input', 'no_tags_input_create' );
add_filter( 'pre_post_tax_input', 'no_tax_input_create' );

function no_tags_input_create($tags_input) {

    $output = array();

    foreach( $tags_input as $tag )
        if( term_exists( $tag, 'post_tag') )
            $output[] = $tag;

    return $output;
}

function no_tax_input_create($tax_input) {

    if( !isset($tax_input['post_tag']) )
        return $tax_input;

    $output = array();
    $tags = explode(',', $tax_input['post_tag']);

    foreach( $tags as $tag )
        if( term_exists( $tag, 'post_tag') )
            $output[] = $tag;

    $tax_input['post_tag'] = implode(',',$output);

    return $tax_input;
}

This is for tags, you can easily extend second function to handle custom taxonomies.

Leave a Comment