Search code examples
phpwordpresstags

Wordpress: Disable Tags only for Posts


I am currently developing a theme for Wordpress 3.8.1. As my theme will not display any tags, so I want do disable them (only from the posts, not from custom post types). But how do I do this? I have tried this, but apparently, it does nothing:

register_taxonomy('post_tag', null);

To be clear: I do not just want to hide the tags in the template files, but I want to disable them completely, so in the backend, there is no menu item for tags under posts.

Is it even possible? I hope so. Thanks for your help!

Update

Additionally, I have tried the following, without any effect:

register_taxonomy('post_tag', array());

and

global $wp_taxonomies;
$taxonomy = 'post_tag';
if(taxonomy_exists($taxonomy))
    unset($wp_taxonomies[$taxonomy]);

Both remove the tags box while editing a post, but there still is the link in the menu pointing to the list of tags!


Solution

  • As of WordPress 3.7, there is an unregister_taxonomy_for_object_type function available for just this sort of thing.

    In your case:

    // Remove tags support from posts
    function myprefix_unregister_tags() {
        unregister_taxonomy_for_object_type('post_tag', 'post');
    }
    add_action('init', 'myprefix_unregister_tags');
    

    View the documentation for this function here.