问题描述

我已经花了最后一天使用 functions.php 文件来为我的客户端网站完全自定义 WordPress 。我感到惊讶的是,我能够完成多少工作,并为我的客户带来多少容易。

我已经删除了没有以管理员身份登录的用户的某些菜单项。我希望 (从我所看到的知道它可以做到) 是找到一种方法来重命名一些菜单项 (管理区域中的左侧栏) 。例如将帖子更改为文章。

如果有人可以提供的代码为 functions.php 文件或指向我的方向我会非常感谢它!

最佳解决方案

以下是更改标签的过程 (我在示例中将帖子更改为”contacts”)

function change_post_menu_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'Contacts';
    $submenu['edit.php'][5][0] = 'Contacts';
    $submenu['edit.php'][10][0] = 'Add Contacts';
    $submenu['edit.php'][15][0] = 'Status'; // Change name for categories
    $submenu['edit.php'][16][0] = 'Labels'; // Change name for tags
    echo '';
}

function change_post_object_label() {
        global $wp_post_types;
        $labels = &$wp_post_types['post']->labels;
        $labels->name = 'Contacts';
        $labels->singular_name = 'Contact';
        $labels->add_new = 'Add Contact';
        $labels->add_new_item = 'Add Contact';
        $labels->edit_item = 'Edit Contacts';
        $labels->new_item = 'Contact';
        $labels->view_item = 'View Contact';
        $labels->search_items = 'Search Contacts';
        $labels->not_found = 'No Contacts found';
        $labels->not_found_in_trash = 'No Contacts found in Trash';
    }
    add_action( 'init', 'change_post_object_label' );
    add_action( 'admin_menu', 'change_post_menu_label' );

要更改菜单顺序,请按以下步骤操作:

// CUSTOMIZE ADMIN MENU ORDER
   function custom_menu_order($menu_ord) {
       if (!$menu_ord) return true;
       return array(
        'index.php', // this represents the dashboard link
        'edit.php', //the posts tab
        'upload.php', // the media manager
        'edit.php?post_type=page', //the posts tab
    );
   }
   add_filter('custom_menu_order', 'custom_menu_order');
   add_filter('menu_order', 'custom_menu_order');

我有代码来删除项目,但它是全局而不是基于用户访问级别

次佳解决方案

你可能想看看 this question

和他们在 gist 上提到的课程

它拥有你所寻找的功能

rename_admin_menu_section()

重命名,例如将帖子更改为文章

您可以删除外观菜单,并为您创建新的首页菜单项

第三种解决方案

我同意.. functions.php 文件提供了很多的灵活性。我需要一些与 functions.php 过滤器和 this plugin 组合使用的相同功能。

从我可以告诉这个插件将完成您的两个问题,它也可以在 Multi-Site 安装情况下运行良好。希望有帮助。

参考文献

注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛。