custom_menu_order
云策文档标注
概述
custom_menu_order 是一个 WordPress 过滤器,用于控制是否启用管理菜单的自定义排序功能。它通常与 'menu_order' 过滤器结合使用,以重新排列菜单项的顺序。
关键要点
- custom_menu_order 过滤器决定是否允许自定义管理菜单排序,默认值为 false。
- 启用后,需配合 'menu_order' 过滤器来指定具体的菜单项顺序。
- 此过滤器自 WordPress 2.8.0 版本引入。
代码示例
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'my_menu_order' );
function my_menu_order( $menu_order ) {
return array( 'index.php', 'edit.php', 'edit.php?post_type=page', 'edit-comments.php' );
}注意事项
示例代码展示了如何将 Dashboard、Posts、Pages 和 Comments 分组到菜单顶部;对于自定义文章类型,需使用 edit.php?post_type=YOURPOSTTYPENAME 格式。
原文内容
Filters whether to enable custom ordering of the administration menu.
Description
See the ‘menu_order’ filter for reordering menu items.
Parameters
$custombool-
Whether custom ordering is enabled. Default false.
Source
if ( apply_filters( 'custom_menu_order', false ) ) {
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 2 content
Steven Lin
Example migrated from Codex:
The following code below groups Dashboard/Posts/Pages/Comments together at the top of the dashboard menu.
If you have a custom post type that you want to add to the group, use the format
edit.php?post_type=YOURPOSTTYPENAMEadd_filter( 'custom_menu_order', '__return_true' ); add_filter( 'menu_order', 'my_menu_order' ); function my_menu_order( $menu_order ) { return array( 'index.php', 'edit.php', 'edit.php?post_type=page', 'edit-comments.php' ); }