Title: wp_admin_bar_site_menu
Published: April 25, 2014
Last modified: May 20, 2026

---

# wp_admin_bar_site_menu( WP_Admin_Bar $wp_admin_bar )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#wp--skip-link--target)

Adds the “Site Name” menu.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#parameters)󠁿

 `$wp_admin_bar`[WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
required

The [WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
instance.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#source)󠁿

    ```php
    function wp_admin_bar_site_menu( $wp_admin_bar ) {
    	// Don't show for logged out users.
    	if ( ! is_user_logged_in() ) {
    		return;
    	}

    	// Show only when the user is a member of this site, or they're a super admin.
    	if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) {
    		return;
    	}

    	$blogname = get_bloginfo( 'name' );

    	if ( ! $blogname ) {
    		$blogname = preg_replace( '#^(https?://)?(www\.)?#', '', get_home_url() );
    	}

    	if ( is_network_admin() ) {
    		/* translators: %s: Site title. */
    		$blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) );
    	} elseif ( is_user_admin() ) {
    		/* translators: %s: Site title. */
    		$blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) );
    	}

    	$title = wp_html_excerpt( $blogname, 40, '&hellip;' );

    	$wp_admin_bar->add_node(
    		array(
    			'id'    => 'site-name',
    			'title' => $title,
    			'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
    			'meta'  => array(
    				'menu_title' => $title,
    			),
    		)
    	);

    	// Create submenu items.

    	if ( is_admin() ) {
    		// Add an option to visit the site.
    		$wp_admin_bar->add_node(
    			array(
    				'parent' => 'site-name',
    				'id'     => 'view-site',
    				'title'  => __( 'Visit Site' ),
    				'href'   => home_url( '/' ),
    			)
    		);

    		if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
    			$wp_admin_bar->add_node(
    				array(
    					'parent' => 'site-name',
    					'id'     => 'edit-site',
    					'title'  => __( 'Manage Site' ),
    					'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
    				)
    			);
    		}
    	} elseif ( current_user_can( 'read' ) ) {
    		// We're on the front end, link to the Dashboard.
    		$wp_admin_bar->add_node(
    			array(
    				'parent' => 'site-name',
    				'id'     => 'dashboard',
    				'title'  => __( 'Dashboard' ),
    				'href'   => admin_url(),
    			)
    		);

    		// Add the appearance submenu items.
    		wp_admin_bar_appearance_menu( $wp_admin_bar );

    		// Add a Plugins link.
    		if ( current_user_can( 'activate_plugins' ) ) {
    			$wp_admin_bar->add_node(
    				array(
    					'parent' => 'site-name',
    					'id'     => 'plugins',
    					'title'  => __( 'Plugins' ),
    					'href'   => admin_url( 'plugins.php' ),
    				)
    			);
    		}
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/admin-bar.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/admin-bar.php#L362)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/admin-bar.php#L362-L449)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#related)󠁿

| Uses | Description | 
| [get_network()](https://developer.wordpress.org/reference/functions/get_network/)`wp-includes/ms-network.php` |

Retrieves network data given a network ID or network object.

  | 
| [wp_html_excerpt()](https://developer.wordpress.org/reference/functions/wp_html_excerpt/)`wp-includes/formatting.php` |

Safely extracts not more than the first $count characters from HTML string.

  | 
| [is_network_admin()](https://developer.wordpress.org/reference/functions/is_network_admin/)`wp-includes/load.php` |

Determines whether the current request is for the network administrative interface.

  | 
| [is_user_admin()](https://developer.wordpress.org/reference/functions/is_user_admin/)`wp-includes/load.php` |

Determines whether the current request is for a user admin screen.

  | 
| [is_blog_admin()](https://developer.wordpress.org/reference/functions/is_blog_admin/)`wp-includes/load.php` |

Determines whether the current request is for a site’s administrative interface.

  | 
| [network_admin_url()](https://developer.wordpress.org/reference/functions/network_admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the network.

  | 
| [get_home_url()](https://developer.wordpress.org/reference/functions/get_home_url/)`wp-includes/link-template.php` |

Retrieves the URL for a given site where the front end is accessible.

  | 
| [WP_Admin_Bar::add_node()](https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/)`wp-includes/class-wp-admin-bar.php` |

Adds a node to the menu.

  | 
| [wp_admin_bar_appearance_menu()](https://developer.wordpress.org/reference/functions/wp_admin_bar_appearance_menu/)`wp-includes/admin-bar.php` |

Adds appearance submenu items to the “Site Name” menu.

  | 
| [is_user_member_of_blog()](https://developer.wordpress.org/reference/functions/is_user_member_of_blog/)`wp-includes/user.php` |

Finds out whether a user is a member of a given blog.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [is_user_logged_in()](https://developer.wordpress.org/reference/functions/is_user_logged_in/)`wp-includes/pluggable.php` |

Determines whether the current visitor is a logged in user.

  | 
| [get_bloginfo()](https://developer.wordpress.org/reference/functions/get_bloginfo/)`wp-includes/general-template.php` |

Retrieves information about the current site.

  | 
| [is_admin()](https://developer.wordpress.org/reference/functions/is_admin/)`wp-includes/load.php` |

Determines whether the current request is for an administrative interface page.

  | 
| [is_multisite()](https://developer.wordpress.org/reference/functions/is_multisite/)`wp-includes/load.php` |

Determines whether Multisite is enabled.

  | 
| [get_current_blog_id()](https://developer.wordpress.org/reference/functions/get_current_blog_id/)`wp-includes/load.php` |

Retrieves the current site ID.

  | 
| [admin_url()](https://developer.wordpress.org/reference/functions/admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the current site.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  |

[Show 15 more](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/?output_format=md#comment-content-7124)
 2.   [Hay](https://profiles.wordpress.org/huskyr/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_admin_bar_site_menu/#comment-7124)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_admin_bar_site_menu%2F%23comment-7124)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_admin_bar_site_menu%2F%23comment-7124)
 4. You can add more links to the ‘View site’ menu. This example will remove the default
    link, re-add it with a different name and also add another link to example.com:
 5.     ```php
        add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
            // Remove default link
            $wp_admin_bar->remove_node( 'view-site' );
    
            // example.com
            $wp_admin_bar->add_node( array(
                'parent' => 'site-name',
                'id'     => 'view-example',
                'title'  => 'Go to example.com',
                'href'   => 'https://www.example.com'
            ) );
    
            // default home
            $wp_admin_bar->add_node( array(
                'parent' => 'site-name',
                'id'     => 'view-home',
                'title'  => 'Go to homepage',
                'href'   => home_url( '/' )
            ) );
        }, 999 ); // Note the 999, this is needed to make sure we can actually remove the default link
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_admin_bar_site_menu%2F%3Freplytocom%3D7124%23feedback-editor-7124)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_admin_bar_site_menu%2F)
before being able to contribute a note or feedback.