wordpress菜单设置_将子菜单添加到WordPress管理栏

wordpress菜单设置

A while back I wrote Add Menu Items to the WordPress Admin Menu, a post detailing how you can add items to the left side, existing "posts" menu bar.  Adding menu items has served me well but it's not as customized as I would like -- I'm still adapting to WordPress instead of WordPress adapting to me.  By creating a custom top bar menu, I can mix and match links all I want!

前一阵子,我写了“ 将菜单项添加到WordPress Admin菜单”一文 ,详细介绍了如何将菜单项添加到左侧的现有“帖子”菜单栏中。 添加菜单项对我很有帮助,但它没有我想要的自定义-我仍在适应WordPress,而不是WordPress对我适应。 通过创建自定义的顶部栏菜单,我可以混合和匹配所有想要的链接!

Like adding functionality to your theme and other admin area, the directives will go in your theme's functions.php file.  The code itself should be self explanatory:

就像在主题和其他管理区域中添加功能一样,这些指令也将放入主题的functions.php文件中。 代码本身应该是自解释的:


function create_dwb_menu() {
	global $wp_admin_bar;

	$menu_id = 'dwb';
	$wp_admin_bar->add_menu(array('id' => $menu_id, 'title' => __('DWB'), 'href' => '/'));
	$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Homepage'), 'id' => 'dwb-home', 'href' => '/', 'meta' => array('target' => '_blank')));
	$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Drafts'), 'id' => 'dwb-drafts', 'href' => 'edit.php?post_status=draft&post_type=post'));
	$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Pending Comments'), 'id' => 'dwb-pending', 'href' => 'edit-comments.php?comment_status=moderated'));
}
add_action('admin_bar_menu', 'create_dwb_menu', 2000);


Setting an id on the parent menu item allows you to use the parent key for submenu items; the rest of the keys are easy to figure out.  With the menu created, you simply need to add the WordPress hook and specificity to add it!

在父菜单项上设置一个id可以使您将parent键用于子菜单项。 其余键很容易弄清楚。 创建菜单后,您只需要添加WordPress钩子并添加特定性即可!

翻译自: https://davidwalsh.name/add-submenu-wordpress-admin-bar

wordpress菜单设置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值