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

文 / @WordPress主题

关于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文件里,然后回到后台刷新一下,就能看到后台管理菜单已经按照我们的需要排好顺序了。

添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。