以下是有效的代码:
add_action(\'admin_bar_menu\', \'toolbar_link_to_mypage\', 999);
function toolbar_link_to_mypage($wp_admin_bar){
global $wp_admin_bar;
$wp_admin_bar->add_menu(array(
\'id\' => \'theme_page\',
\'title\' => __(\'test\', \'test\'),
\'href\' => \'http://mysite.com/my-page/\',
\'meta\' => array(\'class\' => \'test\')
));
$wp_admin_bar->add_menu(array(
\'id\' => \'theme_page_child\',
\'title\' => __(\'Child test\', \'child-test\'),
\'href\' => \'http://mysite.com/my-page/\',
\'meta\' => array(\'class\' => \'child-test\'),
\'parent\' => \'theme_page\'
));
}
首先
add_menu
我在下一个
add_menu
我正在使用另一个属性“parent”,它指的是“parent”的id,这里的“parent”是我们在上面创建的“theme\\u page”。