当前位置:首页文章笔记建站教程WordPress 后台默认选项菜单重命名方法

WordPress 后台默认选项菜单重命名方法

我们知道如何隐藏或是删除 WordPress 主题后台默认的菜单选项,尽管如此,但是 wordpress 默认情况下文章 页英文叫 post, page,有时候,我们开发的时候,也许并不想要这个菜单还是显示着 post,和 page,也许你想要显示为其它的名称,比如“产品”,”联系人”亦或是 其它的名称!当然我们可以自己写一个 post type,移除原来的文章类型,新建的的内容类型可以自己命名,那今天这篇文章给大家讲一下如何重命名 wordpress 后台默的认菜单选项,这个使用场景通常出现在一些企业主题或是小众的主题中,我们需要把 wordpress 默认的一些文章修改为网站导航或是发表小说,或是发表新闻等等,用户提示企业客户更好的增强用户使用体验,在 wordpress 主题开发中也有着不错的优化效果,那我们如何进行修改呢?

修改名称

给个示例代码,在主题的 functions.php 文件下加入以下代码:

  1. function change_post_menu_label() {
  2. global $menu;
  3. global $submenu;
  4. $menu[5][0] = ‘Contacts’;
  5. $submenu[‘edit.php’][5][0] = ‘Contacts’;
  6. $submenu[‘edit.php’][10][0] = ‘Add Contacts’;
  7. $submenu[‘edit.php’][15][0] = ‘Status’; // Change name for categories
  8. $submenu[‘edit.php’][16][0] = ‘Labels’; // Change name for tags
  9. echo ;
  10. }
  11. function change_post_object_label() {
  12. global $wp_post_types;
  13. $labels = &$wp_post_types[‘post’]->labels;
  14. $labels->name = ‘Contacts’;
  15. $labels->singular_name = ‘Contact’;
  16. $labels->add_new = ‘Add Contact’;
  17. $labels->add_new_item = ‘Add Contact’;
  18. $labels->edit_item = ‘Edit Contacts’;
  19. $labels->new_item = ‘Contact’;
  20. $labels->view_item = ‘View Contact’;
  21. $labels->search_items = ‘Search Contacts’;
  22. $labels->not_found = ‘No Contacts found’;
  23. $labels->not_found_in_trash = ‘No Contacts found in Trash’;
  24. }
  25. add_action( ‘init’, ‘change_post_object_label’ );
  26. add_action( ‘admin_menu’, ‘change_post_menu_label’ );

这一个代码中就是把原来的文章 post 的菜单名“post”更改为 Contact 了!

扩展应用

修改菜单排序:

  1. function custom_menu_order($menu_ord) {
  2. if (!$menu_ord) return true;
  3. return array(
  4. ‘index.php’, // this represents the dashboard link
  5. ‘edit.php’, //the posts tab
  6. ‘upload.php’, // the media manager
  7. ‘edit.php?post_type=page’, //the posts tab
  8. );
  9. }
  10. add_filter(‘custom_menu_order’, ‘custom_menu_order’);
  11. add_filter(‘menu_order’, ‘custom_menu_order’);
温馨提示:

文章标题:WordPress 后台默认选项菜单重命名方法

文章链接:https://www.wuyanshuo.cn/680.html

更新时间:2022年04月03日

本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@wuyanshuo.cn我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读无言说网络服务协议

给TA打赏
共{{data.count}}人
人已打赏
建站教程

WordPress 主题集成DPlayer播放M3U8流媒体

2022-4-3 13:47:39

建站教程

WordPress 友情链接个性化调用

2022-4-3 19:58:51

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
'