修改已注册分类的显示用户界面

时间:2018-02-06 作者:Mona Coder

正如你所知\'show_ui\' 布尔选项,用于在注册ataxonomy时在UI上呈现或不呈现分类菜单。

function custom_taxonomy() {

    $labels = array(
        \'name\'                       => \'Taxonomies\',
        \'singular_name\'              => \'Taxonomy\',
        \'menu_name\'                  => \'Taxonomy\',
        \'all_items\'                  => \'All Items\',
        \'parent_item\'                => \'Parent Item\',
        \'parent_item_colon\'          => \'Parent Item:\',
        \'new_item_name\'              => \'New Item Name\',
        \'add_new_item\'               => \'Add New Item\',
        \'edit_item\'                  => \'Edit Item\',
        \'update_item\'                => \'Update Item\',
        \'view_item\'                  => \'View Item\',
        \'separate_items_with_commas\' => \'Separate items with commas\',
        \'add_or_remove_items\'        => \'Add or remove items\',
        \'choose_from_most_used\'      => \'Choose from the most used\',
        \'popular_items\'              => \'Popular Items\',
        \'search_items\'               => \'Search Items\',
        \'not_found\'                  => \'Not Found\',
        \'no_terms\'                   => \'No items\',
        \'items_list\'                 => \'Items list\',
        \'items_list_navigation\'      => \'Items list navigation\',
    );

    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => false,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => true,
    );

    register_taxonomy( \'taxonomy\', array( \'post\' ), $args );

}
add_action( \'init\', \'custom_taxonomy\', 0 );
在注册分类法之后,是否有任何方法可以修改此选项?像任何钩子或过滤器一样切换布尔值functions.php

1 个回复
SO网友:mmm

您可以使用内部使用的此过滤器register_taxonomy

add_filter("register_taxonomy_args", function ($register_taxonomy_args, $name, $object_type) {


    if ("taxonomy" === $name) {

        $register_taxonomy_args["show_ui"] = FALSE;

    }


    return $register_taxonomy_args;

}, 10, 3);

结束

相关推荐