我正在try 从WordPress上购买的主题重命名自定义分类.我已经成功地用我的unctions.php文件中的以下代码将插件从"Director"重命名为"Intutor".

function overwrite_director_slug( $taxonomy, $object_type, $args ){
    if( 'video-director' == $taxonomy ){
        remove_action( current_action(), __FUNCTION__ );
        $args['rewrite'] = array('slug' => 'instructor');
        register_taxonomy( $taxonomy, $object_type, $args );
    }
}
add_action( 'registered_taxonomy', 'overwrite_director_slug', 10, 3 );

如何重命名位于管理菜单中的标签?我想再一次把名字从"主任"改为"教员".(见图)

enter image description here

推荐答案

在现有的定制分类法上重命名您想要的所有内容非常容易.

您可以首先使用get_taxonomy() WordPress function可视化要重命名的分类数据.以下内容显示在前端页脚中,其中包含您的分类(only visible for admins)的所有数据:

add_action('wp_footer', 'wp_footer_script_test_output', 10);
function wp_footer_script_test_output() {
    if( ! current_user_can('administrator') ) return;

    echo '<pre>'. print_r( get_taxonomy('video-director'), true ) . '</pre>';
}

现在,您可以看到可以重命名的所有数据.一旦完成,您就可以删除该代码.

下面将根据您的代码重命名位于管理菜单(and optionally some other labels that you can remove)中的分类标签:

function overwrite_director_slug( $taxonomy, $object_type, $args ){
    if( 'video-director' == $taxonomy ){
        remove_action( current_action(), __FUNCTION__ );
        $args['rewrite'] = array('slug' => 'instructor'); 

        $args['labels']->menu_name = 'Instructor'; // <=== HERE For the "MENU NAME"

        $args['labels']->singular_name = 'Instructor'; // (optional)
        $args['labels']->name = 'Instructor'; // (optional)

        $args['label'] = 'Instructor';  // General label (optional)

        register_taxonomy( $taxonomy, $object_type, $args );
    }
}
add_action( 'registered_taxonomy', 'overwrite_director_slug', 10, 3 );

代码位于您的子主题的unctions.php文件中(或在插件中).经过测试和工作.

Php相关问答推荐

CodeIgniter AJAX表格提交中的CSRF token 再生问题

Laravel通过(扩展FormRequest类)方法验证表单请求

从WooCommerce邮箱通知中的订单详细信息中删除产品列表

在WooCommerce中执行一次银行电汇确认付款代码

我如何知道BaseController中当前运行的是哪个控制器?

在Woocommerce变量产品中的标签附近显示所选属性选项名称

WooCommerce基于元数据的自定义范围目录排序

在WooCommerce中禁用特定日期之前的免费送货

在冲突和几何上插入的Postgres参数化查询在PHP中不起作用

目标类[Set_Locale]不存在.拉威尔

如何用Ubuntu 22.04在VSCode中启用XDebug

为WooCommerce中存储一些数据的购物车项目添加复选框

在WooCommerce中以编程方式添加特定产品后,将价格设置为零

htaccess 配置提供静态文件和动态文件

用自定义代码替换 WooCommerce 单一产品简短描述

如何正确判断 PHP 是否已正确配置为使用 DOMDocument?

Google Sheets PHP API - 添加多个选项卡时出现问题

如何从此字符串创建 Carbon 对象:2022-06-21T05:52:46.648533678Z?

是否有适用于 Windows 的真正 64 位版本的 PHP 5.6?

如何在php中获取大于50的年龄