Function Signature:
wp_admin_bar_new_content_menu
Function Description:
Adds "Add New" menu.
Function Examples:
⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Adding a new menu item to the admin bar for creating a new post
function custom_admin_bar_menu() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'new_post',
'title' => 'New Post',
'href' => admin_url( 'post-new.php' ),
'parent' => 'new-content'
));
}
add_action( 'wp_before_admin_bar_render', 'custom_admin_bar_menu' );
// Example 2: Customizing the new content menu in the admin bar to include a link to create a new page
function custom_admin_bar_menu() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'new_page',
'title' => 'New Page',
'href' => admin_url( 'post-new.php?post_type=page' ),
'parent' => 'new-content'
));
}
add_action( 'wp_before_admin_bar_render', 'custom_admin_bar_menu' );
// Example 3: Removing the default new content menu item from the admin bar and adding a custom one for creating a new custom post type
function custom_admin_bar_menu() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu( 'new-content' );
$wp_admin_bar->add_menu( array(
'id' => 'new_custom_post',
'title' => 'New Custom Post',
'href' => admin_url( 'post-new.php?post_type=custom_post_type' )
));
}
add_action( 'wp_before_admin_bar_render', 'custom_admin_bar_menu' );