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.  
  12. function change_post_object_label() {
  13.         global $wp_post_types;
  14.         $labels = &$wp_post_types['post']->labels;
  15.         $labels->name = 'Contacts';
  16.         $labels->singular_name = 'Contact';
  17.         $labels->add_new = 'Add Contact';
  18.         $labels->add_new_item = 'Add Contact';
  19.         $labels->edit_item = 'Edit Contacts';
  20.         $labels->new_item = 'Contact';
  21.         $labels->view_item = 'View Contact';
  22.         $labels->search_items = 'Search Contacts';
  23.         $labels->not_found = 'No Contacts found';
  24.         $labels->not_found_in_trash = 'No Contacts found in Trash';
  25.     }
  26.     add_action( 'init', 'change_post_object_label' );
  27.     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 后台默认选项菜单重命名方法

已有 233 人购买
查看演示升级 VIP立刻购买

收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!