更改管理员菜单标签
-
-
也许您应该将其分为两个不同的问题:*"重命名管理菜单项" *和*"更改管理菜单项的顺序" *?这将帮助您获得有关问题的更多视图.Maybe you should split this up into two different questions: *"Renaming admin menu items"* and *"Changing the order of admin menu items"*? This will help you get more views for your question.
- 0
- 2011-02-13
- Jan Fabry
-
5 个回答
- 投票数
-
- 2011-02-12
以下是更改标签的过程(在我的示例中,我将帖子更改为"联系人")
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');
我有删除项目的代码,但这是全局的,而不是基于用户访问级别的
Here's the process to change the labels (I changed posts to "contacts" in my example)
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');
I've got code to remove items, but it's globally and not based on user access level
-
非常感谢!现在,我只需要找到一种将子菜单项(例如,菜单)移动为主菜单按钮的方法.有什么想法吗?This is excellent thanks! Now I just need to find a way of moving a sub menu item (ex. Menus) as a main menu button. Any idea on that?
- 0
- 2011-02-13
- Adam
-
还没有测试过,但是看看是否在数组中添加"nav-menus.php"会使它向上移动.Haven't tested, but see if adding 'nav-menus.php' to the array moves it up.
- 0
- 2011-02-13
- Norcross
-
抱歉不行.这一直困扰着我.我只是希望能够将菜单和小部件设置为它们自己的按钮,因此对于客户端来说更容易.不过谢谢你的尝试Unfortunately no. This has been the one part that has been bugging me. I just want to be able to have the menus and widgets be their own buttons so it is easier for clients. Thank you though for trying
- 0
- 2011-02-13
- Adam
-
@Norcross这很好,但是是否可以对其进行修改,使其可以包含文本域以进行翻译?@Norcross This is great, but is it possible to adapt it so that it can include the text-domain for translation purposes?
- 0
- 2014-11-12
- Phill Healey
-
@PhillHealey此函数根本不包含任何用于标记的数据,而仅包含订单本身.@PhillHealey this function doesn't contain any data for labeling at all, rather, just the order itself.
- 0
- 2014-11-12
- Norcross
-
@Norcross当然.我想我写这篇文章时脑子里有太多的任务要处理.;-)@Norcross Of course. I think I had too many tasks being juggled in my head when I wrote that. ;-)
- 0
- 2014-11-13
- Phill Healey
-
小提示.我认为对钩子" custommenu_order"返回true是足够的.-`add_filter('custom_menu_order','__return_true');`订单来自`menu_order`.Small hint. I think it is right and enough to return true for the hook `custom_menu_order`. - `add_filter( 'custom_menu_order', '__return_true' );` The order comes from `menu_order`.
- 0
- 2015-03-30
- bueltge
-
@Ivan在下面的答案更好,因为它使用了内置的过滤器`post_type_labels _ {$post_type}`,它更干净.@Ivan's answer below is better since it uses the built in filter `post_type_labels_{$post_type}`, which is cleaner.
- 0
- 2018-02-20
- Ryan
-
- 2017-02-19
要重命名默认帖子类型(或其他任何与此类型的帖子),只需使用过滤器
post_type_labels_{$post_type}
.对于默认的post
,它将为post_type_labels_post
.下面的代码中是标签的完整列表(WP 4.7.1
).您不必更改所有内容.add_filter( 'post_type_labels_post', 'news_rename_labels' ); /** * Rename default post type to news * * @param object $labels * @hooked post_type_labels_post * @return object $labels */ function news_rename_labels( $labels ) { # Labels $labels->name = 'News'; $labels->singular_name = 'News'; $labels->add_new = 'Add News'; $labels->add_new_item = 'Add News'; $labels->edit_item = 'Edit News'; $labels->new_item = 'New News'; $labels->view_item = 'View News'; $labels->view_items = 'View News'; $labels->search_items = 'Search News'; $labels->not_found = 'No news found.'; $labels->not_found_in_trash = 'No news found in Trash.'; $labels->parent_item_colon = 'Parent news'; // Not for "post" $labels->archives = 'News Archives'; $labels->attributes = 'News Attributes'; $labels->insert_into_item = 'Insert into news'; $labels->uploaded_to_this_item = 'Uploaded to this news'; $labels->featured_image = 'Featured Image'; $labels->set_featured_image = 'Set featured image'; $labels->remove_featured_image = 'Remove featured image'; $labels->use_featured_image = 'Use as featured image'; $labels->filter_items_list = 'Filter news list'; $labels->items_list_navigation = 'News list navigation'; $labels->items_list = 'News list'; # Menu $labels->menu_name = 'News'; $labels->all_items = 'All News'; $labels->name_admin_bar = 'News'; return $labels; }
如果要国际化支持,只需使用
__( $text, $textdomain )
像:$labels->name = __( 'News', 'textdomain' );
我从文件
wp-includes/post.php
中找到过滤器:wp-includes/post.php
:/** * Filter the labels of a specific post type. * * The dynamic portion of the hook name, `$post_type`, refers to * the post type slug. * * @since 3.5.0 * * @see get_post_type_labels() for the full list of labels. * * @param object $labels Object with labels for the post type as member variables. */ $labels = apply_filters( "post_type_labels_{$post_type}", $labels );
To rename default post type (or any other for that matter) just use filter
post_type_labels_{$post_type}
. For defaultpost
it will bepost_type_labels_post
. In the code below is the full list of labels (WP 4.7.1
). You do not have to change everything.add_filter( 'post_type_labels_post', 'news_rename_labels' ); /** * Rename default post type to news * * @param object $labels * @hooked post_type_labels_post * @return object $labels */ function news_rename_labels( $labels ) { # Labels $labels->name = 'News'; $labels->singular_name = 'News'; $labels->add_new = 'Add News'; $labels->add_new_item = 'Add News'; $labels->edit_item = 'Edit News'; $labels->new_item = 'New News'; $labels->view_item = 'View News'; $labels->view_items = 'View News'; $labels->search_items = 'Search News'; $labels->not_found = 'No news found.'; $labels->not_found_in_trash = 'No news found in Trash.'; $labels->parent_item_colon = 'Parent news'; // Not for "post" $labels->archives = 'News Archives'; $labels->attributes = 'News Attributes'; $labels->insert_into_item = 'Insert into news'; $labels->uploaded_to_this_item = 'Uploaded to this news'; $labels->featured_image = 'Featured Image'; $labels->set_featured_image = 'Set featured image'; $labels->remove_featured_image = 'Remove featured image'; $labels->use_featured_image = 'Use as featured image'; $labels->filter_items_list = 'Filter news list'; $labels->items_list_navigation = 'News list navigation'; $labels->items_list = 'News list'; # Menu $labels->menu_name = 'News'; $labels->all_items = 'All News'; $labels->name_admin_bar = 'News'; return $labels; }
If you want internationalization support, just use
__( $text, $textdomain )
like:$labels->name = __( 'News', 'textdomain' );
I found the filter in function:
get_post_type_labels()
from a filewp-includes/post.php
:/** * Filter the labels of a specific post type. * * The dynamic portion of the hook name, `$post_type`, refers to * the post type slug. * * @since 3.5.0 * * @see get_post_type_labels() for the full list of labels. * * @param object $labels Object with labels for the post type as member variables. */ $labels = apply_filters( "post_type_labels_{$post_type}", $labels );
-
Norcross的答案在撰写本文时可能是最好的,但这是使用本地过滤器完成相同结果的一种更为简洁的方法.Norcross's answer may have been the best at the time it was written, but this is a far cleaner approach that uses a native filter to accomplish the same outcome.
- 2
- 2018-02-20
- Ryan
-
写完原件后,我同意这个过滤器会更好.Having written the original, I agree this filter is much better.
- 2
- 2018-11-26
- Norcross
-
- 2011-02-12
我同意.
functions.php
文件提供了很多灵活性.我需要与您结合使用functions.php
过滤器和此插件.据我所知..这个插件可以解决您的两个问题,并且在Multi-Site安装情况下也能很好地工作.希望有帮助.
I agree.. The
functions.php
file gives lots of flexibility. I've needed some of the same functionality that you described with a combination offunctions.php
filters and this plugin.From what I can tell..this plugin would accomplish both of your issues and it works well in Multi-Site install situations too. Hope that helps.
-
糟糕...射击,对不起,只是看到了一些不想使用插件的信息.绝对有一些方法可以仅通过Functions.php转换选项卡名称和位置.对我来说,在走了这条路之后(尝试使用免费插件),我认为额外的编码是不值得的……因为该插件的使用非常简单.对不起,我以前错过了这个标准.Ooops...shoot, sorry, just saw the bit about not wanting to use a plugin. There are definitely ways to go about translating the tab names and placements with just the Functions.php. For me, after heading down this path (trying to be plugin-free for this) I decided that the extra coding just wasn't worth it...given how easy that plugin was to use. Sorry I missed that criteria before.
- 0
- 2011-02-12
- Ross
-
没问题,罗斯,我还是要研究一下.谢谢No problem Ross, I am going to look into it anyway. Thanks
- 0
- 2011-02-13
- Adam
-
- 2011-02-12
您可能希望查看此问题
以及他们在要点
上提到的课程包含您正在寻找的功能
rename_admin_menu_section()
重命名例如将文章更改为文章
,您可以删除外观菜单并为其创建新的首页菜单项
You might want to look at this question
and the class they mention there on gist
which holds functions that you ara looking for
rename_admin_menu_section()
to rename for instance change Posts to Articles
and you can remove the appearances menu and create you new top page menu item for
-
- 2016-02-04
Norcross上面的示例是正确的,但是我需要国际化的可能性.如果我有声誉,这将是Norcross的回答下的评论,但由于我没有,因此我将修改后的代码放在此处. "i18n_context"是翻译上下文的任意名称空间,例如,可以是您的插件或主题的名称.
function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][10][0] = __('Add Contacts', 'i18n_context'); $submenu['edit.php'][15][0] = __('Status', 'i18n_context'); // Change name for categories $submenu['edit.php'][16][0] = __('Labels', 'i18n_context'); // Change name for tags echo ''; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = __('Contacts', 'i18n_context'); $labels->singular_name = __('Contact', 'i18n_context'); $labels->add_new = __('Add Contact', 'i18n_context'); $labels->add_new_item = __('Add Contact', 'i18n_context'); $labels->edit_item = __('Edit Contacts', 'i18n_context'); $labels->new_item = __('Contact', 'i18n_context'); $labels->view_item = __('View Contact', 'i18n_context'); $labels->search_items = __('Search Contacts', 'i18n_context'); $labels->not_found = __('No Contacts found', 'i18n_context'); $labels->not_found_in_trash = __('No Contacts found in Trash', 'i18n_context'); } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
Norcross's example above is right on, but I needed the possibility of internationalization. If I had the reputation, this would be a comment under Norcross's answer, but since I don't, i'll just put the modified code here. 'i18n_context' is an arbitrary namespace for the translation context, this could be the name of your plugin or theme for example.
function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][10][0] = __('Add Contacts', 'i18n_context'); $submenu['edit.php'][15][0] = __('Status', 'i18n_context'); // Change name for categories $submenu['edit.php'][16][0] = __('Labels', 'i18n_context'); // Change name for tags echo ''; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = __('Contacts', 'i18n_context'); $labels->singular_name = __('Contact', 'i18n_context'); $labels->add_new = __('Add Contact', 'i18n_context'); $labels->add_new_item = __('Add Contact', 'i18n_context'); $labels->edit_item = __('Edit Contacts', 'i18n_context'); $labels->new_item = __('Contact', 'i18n_context'); $labels->view_item = __('View Contact', 'i18n_context'); $labels->search_items = __('Search Contacts', 'i18n_context'); $labels->not_found = __('No Contacts found', 'i18n_context'); $labels->not_found_in_trash = __('No Contacts found in Trash', 'i18n_context'); } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
我已经花了最后一天使用functions.php文件为我的客户站点完全自定义WordPress.我为自己能够完成的工作量以及为客户带来帮助的便捷程度感到惊讶.
我已为未以管理员身份登录的用户删除了某些菜单项.我希望(从阅读的内容中知道可以完成)是找到一种方法来重命名某些菜单项(管理区域的左侧边栏).例如,将文章更改为文章.
如果任何人都可以提供functions.php文件的代码,或向我指出方向,我将不胜感激!