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菜单设置