Random WordPress Function

Learn about a new WordPress function every day!


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 WordPress admin bar for logged-in users
function custom_admin_bar_menu() {
    global $wp_admin_bar;
    
    $wp_admin_bar->add_menu( array(
        'id' => 'new_content',
        'title' => 'New Content',
        'href' => admin_url( 'post-new.php' ),
        'parent' => 'new-content-menu',
    ));
}
add_action( 'wp_before_admin_bar_render', 'custom_admin_bar_menu' );
// Example 2: Removing a default menu item from the WordPress admin bar
function remove_default_admin_menu() {
    global $wp_admin_bar;
    
    $wp_admin_bar->remove_menu( 'new-content-menu' );
}
add_action( 'wp_before_admin_bar_render', 'remove_default_admin_menu' );
// Example 3: Customizing the appearance of a menu item in the WordPress admin bar
function customize_admin_menu_item() {
    global $wp_admin_bar;
    
    $wp_admin_bar->add_menu( array(
        'id' => 'new_content',
        'title' => 'Add New Post',
        'href' => admin_url( 'post-new.php' ),
        'parent' => 'new-content-menu',
        'meta' => array(
            'class' => 'custom-menu-item',
            'target' => '_blank',
        ),
    ));
}
add_action( 'wp_before_admin_bar_render', 'customize_admin_menu_item' );