我也有类似的情况。我的自定义帖子类型在管理栏下显示为Artifact, 但我的客户希望它能排在榜首。再加上Media 和User 其实并不需要。
我的方法是首先使用
remove_node 删除除我的自定义帖子类型之外的所有帖子,然后放回我想要的
add_nodeadd_action( \'wp_before_admin_bar_render\', \'portfolio_adminbar\' );
function portfolio_adminbar() {
global $wp_admin_bar;
// get node for New + menu node
$new_content_node = $wp_admin_bar->get_node(\'new-content\');
// change URL for node, edit for prefered link
$new_content_node->href = admin_url( \'post-new.php?post_type=portfolio\' );
// Update New + menu node
$wp_admin_bar->add_node($new_content_node);
// remove all items from New Content menu
$wp_admin_bar->remove_node(\'new-post\');
$wp_admin_bar->remove_node(\'new-media\');
$wp_admin_bar->remove_node(\'new-page\');
$wp_admin_bar->remove_node(\'new-user\');
// add back the new Post link
$args = array(
\'id\' => \'new-post\',
\'title\' => \'Blog Post\',
\'parent\' => \'new-content\',
\'href\' => admin_url( \'post-new.php\' ),
\'meta\' => array( \'class\' => \'ab-item\' )
);
$wp_admin_bar->add_node( $args );
// add back the new Page
$args = array(
\'id\' => \'new-page\',
\'title\' => \'Page\',
\'parent\' => \'new-content\',
\'href\' => admin_url( \'post-new.php?post_type=page\' ),
\'meta\' => array( \'class\' => \'ab-item\' )
);
$wp_admin_bar->add_node( $args );
}
以下是我的菜单: