Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 252
Lars Ebert Avatar asked Mar 27 '14 15:03

Lars Ebert


People also ask

Can I hide tags in WordPress?

In WordPress, tags are automatically placed on the index and post pages in most themes. There may be times when you wish to hide tags in WordPress. This can be done inside WordPress by using the built-in editor to remove the PHP code that displays the tags.

How do I manage tags in WordPress?

Following are the simple steps to Edit Tags in WordPress. Step (1) − Click on Posts → Tags in WordPress. Edit − Click on Edit option in Tags section as shown in the following screen. You can edit any of the required field, and then click on Update button as shown in the following screen.


2 Answers

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.

like image 167
zgreen Avatar answered Oct 16 '22 21:10

zgreen


Paste this code into your functions.php

add_action( 'admin_menu', 'myprefix_remove_meta_box');
function myprefix_remove_meta_box(){
   remove_meta_box( 'tagsdiv-post_tag','post','normal' );
}

tags meta box has a class of tagsdiv-post_tag, so this will remove the tags meta box

OR

add_action('init', 'remove_tags');
function remove_tags(){
    register_taxonomy('post_tag', array());
}

if you completely want to remove it

like image 28
user3293145 Avatar answered Oct 16 '22 20:10

user3293145