简体   繁体   中英

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!

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM