如何向WordPress Admin Bar中添加菜单

林继 WordPress 1,738 共写了1202个字 (2012-12-22 15:01:21) 没有评论 打印 扫描二维码 百度未收录

将代码放到functions.php中

add_action(‘admin_bar_menu’, ‘add_toolbar_items’, 100);
function add_toolbar_items($admin_bar){
$admin_bar->add_menu( array(
‘id’ => ‘my-item’,
‘title’ => ‘My Item’,
‘href’ => ‘#’,
‘meta’ => array(
‘title’ => __(‘My Item’),
),
));
$admin_bar->add_menu( array(
‘id’ => ‘my-sub-item’, // 自定义链接的 ID
‘parent’ => ‘my-item’, // ‘false’ 为添加住菜单,也可以输入父级菜单的 ID
‘title’ => ‘My Sub Menu Item’, // 自定义链接标题
‘href’ => ‘#’, // 链接地址
‘meta’ => array(
‘title’ => __(‘My Sub Menu Item’),
‘target’ => ‘_blank’,
‘class’ => ‘my_menu_item_class’
), // 用来设置自定义链接属性选项的一个数组:array( ‘html’ => ”, ‘class’ => ”, ‘onclick’ => ”, target => ”, title => ” );
));
$admin_bar->add_menu( array(
‘id’ => ‘my-second-sub-item’,
‘parent’ => ‘my-item’,
‘title’ => ‘My Second Sub Menu Item’,
‘href’ => ‘#’,
‘meta’ => array(
‘title’ => __(‘My Second Sub Menu Item’),
‘target’ => ‘_blank’,
‘class’ => ‘my_menu_item_class’
),
));
}

不指定parent参数,则为顶级菜单,指定parent则为次级菜单。

[level l=10]

add_action(‘admin_bar_menu’, ‘add_toolbar_items’, 100);
function add_toolbar_items($admin_bar){
$admin_bar->add_menu( array(
‘id’ => ‘delete’,
‘title’ => ‘删除’,
‘href’ => get_delete_post_link($current_object->term_id)
));
$admin_bar->add_menu( array(
‘id’ => ‘lum’,
‘title’ => ‘LUM交易成功客户名单’,
‘href’ => ‘/sale’
));
$admin_bar->add_menu( array(
‘id’ => ‘vpn’,
‘title’ => ‘OpenVPN’,
‘href’ => ‘/6634.html’
));
}

[/level]

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

< >