您的当前位置:首页 > 知识博客 > wordpress建站

WordPress 自定义后台管理菜单顺序

时间:2024-04-05


关于WordPress后台菜单的排序

现如今,越来越多的网站都采用了WordPress作为网站建设的核心工具。添加多个自定义文章类型会导致后台菜单顺序混乱,因此对后台菜单进行排序显得非常有必要。如果通过代码添加自定义文章类型,则只需要注意添加的顺序即可。如果通过插件添加,则需要利用WordPress的‘menu_order’这个过滤器进行调整。

对WordPress后台管理菜单排序的代码

function custom_menu_order($menu_ord){
  if(!$menu_ord) return true;
  return array(
    'index.php', // 这个代表着仪表盘
    'edit.php?post_type=events', // 自定义文章类型菜单
    'edit.php?post_type=news',
    'edit.php?post_type=articles',
    'edit.php?post_type=faqs',
    'edit.php?post_type=mentors',
    'edit.php?post_type=testimonials',
    'edit.php?post_type=services',
    'edit.php?post_type=page', // 默认的页面菜单
    'edit.php', // 默认的文章菜单
  );
}
add_filter('custom_menu_order', 'custom_menu_order');
add_filter('menu_order', 'custom_menu_order');

从代码中可以看出,通过后台网址实现排序非常方便。只需要将以上代码添加到当前WordPress主题的function.php文件里,然后回到后台刷新一下,就能看到后台管理菜单已经按照我们的需要排好顺序了。


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 58.bj.cn


Whatsapp
Powered by RRZCMS