生命不息,奋斗不止/创造价值-传递价值-获得价值
所谓迷茫,就是才华配不上梦想 每一个让你难堪的现在,都有一个不够努力的曾经

wordpress菜单名称重命名

WordPress系统源于一个blog平台,慢慢地发展到今天的这样一个功能强大的cms系统!

尽管如此,但是wordpress默认情况下文章页英文叫post, page,有时候,我们开发的时候,也许并不想要这个菜单还是显示着post,和page,也许你想要显示为其它的名称,比如“产品”,”联系人”亦或是其它的名称!

当然我们可以自己写一个post type,移除原来的文章类型,新建的的内容类型可以自己命名,但是其实我们还有一个更好的方法对原来系统的内容类型菜单名称进行重命名:

看下面的一个国外的高手的代码:

<?php 
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' );
To change the menu order, go with this:
 
// 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');
?>

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

参考资料:http://wordpress.stackexchange.com/questions/9211/changing-admin-menu-labels

原文地址:http://markchen.me/the-wordpress-menu-name-rename/

赞(0)
未经允许不得转载:jack361博客 » wordpress菜单名称重命名

如果你爱我或恨我,请↓

联系我