menu_order
云策文档标注
概述
menu_order 过滤器用于自定义 WordPress 管理后台菜单项的显示顺序。必须先启用 custom_menu_order 过滤器才能使其生效。
关键要点
- menu_order 过滤器接收一个有序数组参数 $menu_order,用于指定菜单项的顺序。
- 使用前需通过 add_filter( 'custom_menu_order', '__return_true' ) 启用自定义菜单排序功能。
- 未在数组中提及的菜单项将排在提及的菜单项之后,并保持其默认相对顺序。
代码示例
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'custom_menu_order' );
function custom_menu_order() {
return array( 'index.php', 'edit.php', 'edit-comments.php' );
}
原文内容
Filters the order of administration menu items.
Description
A truthy value must first be passed to the ‘custom_menu_order’ filter for this filter to work. Use the following to enable custom menu ordering:
add_filter( 'custom_menu_order', '__return_true' );
Parameters
$menu_orderarray-
An ordered array of menu items.
Source
$menu_order = apply_filters( 'menu_order', $menu_order );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 2 content
Steven Lin
Example Migrated from Codex:
The example below orders menus with Dashboard, Posts, and Comments in the first menu group. The remaining menus follow in their usual order.
add_filter( 'custom_menu_order', '__return_true' ); add_filter( 'menu_order', 'custom_menu_order' ); function custom_menu_order() { return array( 'index.php', 'edit.php', 'edit-comments.php' ); }