如何从 Wordpress 中删除分类法?

发布于 2024-10-04 13:02:29 字数 75 浏览 1 评论 0原文

我正在创建不同的自定义帖子类型和分类法,并且我想从默认的“帖子”帖子类型中删除“帖子标签”分类法。我该怎么做呢?

谢谢。

I'm creating different custom post types and taxonomies and I want to remove the 'Post Tags' taxonomy from the default 'Posts' post type. How do I go about doing this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

过期以后 2024-10-11 13:02:29

我建议你不要搞乱实际的全局。简单地从帖子类型中取消注册分类法更安全:register_taxonomy 用于创建和修改。

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

要删除侧边栏菜单条目:

// Remove menu
function remove_menus(){
    remove_menu_page('edit-tags.php?taxonomy=post_tag'); // Post tags
}

add_action( 'admin_menu', 'remove_menus' );

I suggest you don't mess with the actual global. Its safer to simply deregister the taxonomy from the post type: register_taxonomy is used for both creation and modification.

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

To remove the sidebar menu entry:

// Remove menu
function remove_menus(){
    remove_menu_page('edit-tags.php?taxonomy=post_tag'); // Post tags
}

add_action( 'admin_menu', 'remove_menus' );
谁的年少不轻狂 2024-10-11 13:02:29

也许技术上更正确的方法是使用 unregister_taxonomy_for_object_type

add_action( 'init', 'unregister_tags' );

function unregister_tags() {
    unregister_taxonomy_for_object_type( 'post_tag', 'post' );
}

Perhaps a more technically correct method would be to use unregister_taxonomy_for_object_type

add_action( 'init', 'unregister_tags' );

function unregister_tags() {
    unregister_taxonomy_for_object_type( 'post_tag', 'post' );
}
情深已缘浅 2024-10-11 13:02:29

完全注销并删除(最低 PHP 版本 5.4!)

add_action('init', function(){
        global $wp_taxonomies;
        unregister_taxonomy_for_object_type( 'category', 'post' );
        unregister_taxonomy_for_object_type( 'post_tag', 'post' );
        if ( taxonomy_exists( 'category'))
            unset( $wp_taxonomies['category']);
        if ( taxonomy_exists( 'post_tag'))
            unset( $wp_taxonomies['post_tag']);
        unregister_taxonomy('category');
        unregister_taxonomy('post_tag');
    });

Total unregister and remove (minimal PHP version 5.4!)

add_action('init', function(){
        global $wp_taxonomies;
        unregister_taxonomy_for_object_type( 'category', 'post' );
        unregister_taxonomy_for_object_type( 'post_tag', 'post' );
        if ( taxonomy_exists( 'category'))
            unset( $wp_taxonomies['category']);
        if ( taxonomy_exists( 'post_tag'))
            unset( $wp_taxonomies['post_tag']);
        unregister_taxonomy('category');
        unregister_taxonomy('post_tag');
    });
月亮是我掰弯的 2024-10-11 13:02:29

在显示“taxonomy_to_remove”的地方,您可以输入要删除的分类法。例如,您可以将其替换为现有的 post_tagcategory

add_action( 'init', 'unregister_taxonomy');
function unregister_taxonomy(){
    global $wp_taxonomies;
    $taxonomy = 'taxonomy_to_remove';
    if ( taxonomy_exists( $taxonomy))
        unset( $wp_taxonomies[$taxonomy]);
}

Where it says 'taxonomy_to_remove' is where you'll enter the taxonomy you want to remove. For instance you can replace it with the existing, post_tag or category.

add_action( 'init', 'unregister_taxonomy');
function unregister_taxonomy(){
    global $wp_taxonomies;
    $taxonomy = 'taxonomy_to_remove';
    if ( taxonomy_exists( $taxonomy))
        unset( $wp_taxonomies[$taxonomy]);
}
清风挽心 2024-10-11 13:02:29

有一个新功能可以从 WordPress 中删除分类。

使用 unregister_taxonomy( string $taxonomy ) 函数

查看详细信息:https:// developer.wordpress.org/reference/functions/unregister_taxonomy/

There is new function to remove taxonomy from WordPress.

Use unregister_taxonomy( string $taxonomy ) function

See details: https://developer.wordpress.org/reference/functions/unregister_taxonomy/

冷清清 2024-10-11 13:02:29

在“admin_init”挂钩中使用它而不是“init”

function unregister_taxonomy(){
    register_taxonomy('post_tag', array());
}
add_action('admin_init', 'unregister_taxonomy');

Use it in 'admin_init' hook insetead not 'init'

function unregister_taxonomy(){
    register_taxonomy('post_tag', array());
}
add_action('admin_init', 'unregister_taxonomy');
っ左 2024-10-11 13:02:29

add_action('admin_menu', 'remove_menu_items');
函数remove_menu_items() {
remove_submenu_page('edit.php','edit-tags.php?taxonomy=post_tag');
}

add_action('admin_menu', 'remove_menu_items');
function remove_menu_items() {
remove_submenu_page('edit.php','edit-tags.php?taxonomy=post_tag');
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文