I need to add a dropdown menu to Wordpress in the admin bar to include multiple links. What is the best solution?
1条回答 默认 最新
- doupa1883 2015-05-29 17:04关注
I was looking for the answer to this question for a while and couldn't find the solution on here so I thought this would help! I found a great blog post and the perfect solution to my question:
http://davidwalsh.name/add-submenu-wordpress-admin-bar
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:
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!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 三种调度算法报错 有实例
- ¥15 关于#python#的问题,请各位专家解答!
- ¥200 询问:python实现大地主题正反算的程序设计,有偿
- ¥15 smptlib使用465端口发送邮件失败
- ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
- ¥15 对于squad数据集的基于bert模型的微调
- ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
- ¥20 steam下载游戏占用内存
- ¥15 CST保存项目时失败
- ¥20 java在应用程序里获取不到扬声器设备