Strict tag list – user should choose only existing tags for posts

While selecting tags for the posts the user is able to create new tags on fly.

For example we have the tag ‘animal’ but the user misstpye it as ‘aminal’ – and WordPress creates it.

Read More

In our blog the strict tag structure is essential. How can I disable this function?

Edit

Solution added.

Related posts

Leave a Reply

2 comments

  1. YOu can deactive the default tag feature and add via plugin an custom taxonomie, that only list your created tags, like category meta box. Its also possible to design this how the tag meta box.

  2. Solution

    Adding a hook to the create_term action works. Two things to do:

    • Check the referer, and if it comes from ‘post.php’, die
    • but before stopping, delete the new (and unwanted) tag with wp_delete_term($term_id, “post_tag”);

    Source code as plugin

    <?php
    /*
    Plugin Name: Tag Checker
    */
    
    add_action('create_term', 'tag_checker_hook');
    
    function tag_checker_hook($term_id) 
    {
        $referer = $_SERVER['HTTP_REFERER'];
    
        if (strpos($referer, "/wp-admin/post.php") !== false)
        {
            // Delete it
            wp_delete_term($term_id, "post_tag");
    
            wp_die("You are not able to create new tags.");
        }
    }
    
    ?>