WordPress发展到今天,已经不仅仅是一个博客平台了,更是一个CMS,二次开发更可以是企业站、商务网站。在对WordPress 进行二次开发时候,可能出于某种原因,需要对WordPress 后台管理菜单名称进行重命名,比如说文章页(post),想要显示为其它的名称,比如“产品”,那么可以通过以下代码来实现重命名。
给个示例代码,在主题的functions.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' ); |
---|
该代码就是把原来的文章post的菜单名“post”更改为Contact。
代码来源:点击查看,感谢原作者。