How To Remove and Add Visit Site Menu From WordPress Admin Bar?

Using This Code, you can remove the 'Visit Site' Section admin bar drop down and add it to admin bar menu section


// Add Visit Site in ID Section   -- Bonus

add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {

    if ( ! is_admin() ) {
        return;
    }

    /** @var WP_Admin_Bar $wp_admin_bar */
    $wp_admin_bar->remove_node( 'view-site' );

    $wp_admin_bar->add_menu( array(
        'id'    => 'view-site',
        'title' => __( 'Visit Site' ),
        'href'  => home_url( '/' ),
    ) );
}, 31 ); // After `wp_admin_bar_site_menu()` at 30.


// Another Way

add_action( 'admin_bar_menu', 'make_parent_node', 999 );
function make_parent_node( $wp_admin_bar ) {
    if ( ! is_admin() ) { return; }  // end function if not in admin back-end, credit @Rarst
    $args = array(
        'id'     => 'view-site',  // id of the existing child node (View Site)
        'title'  => 'Visit Site', // alter the title of existing node (optional)
        'parent' => false         // set parent to false to make it a top level (parent) node
    );
    $wp_admin_bar->add_node( $args );
}


// Add Visit Site in ID Section   -- Bonus

Comments

Popular posts from this blog

Register Custom Post Type

Remove Add New Post Sub Menu From Custom Post