Customize site label in multisite

Hi guys, I'm building a site with a blog and a corporate site. To avoid multiple logins, I have created a multisite network like this:

corporatesite.com (Main site)
blog.corporatesite.com (Blog)

For SEO we want the site title to be the same, e.g. "Acme Inc". But in the Dashboard, under the My Sites dropdown, there is now 2 "Acme Inc" items. How can I keep the site title the same, but assign a label for each site so that the My Sites dropdown will show "Main site" and "Blog"?

I hope you have a good solution for me, thanks!

  • Vinod Dalvi

    Hi @blogjunkie,

    I hope you are well today and thank you for your question.

    To achieve this could you please try using the attached small plugin that contains the following code?

    function vvd_remove_my_sites( $wp_admin_bar ) {
        $wp_admin_bar->remove_node('my-sites');
    }
    
    add_action( 'admin_bar_menu', 'vvd_remove_my_sites', 999 );
    
    function vvd_my_sites($admin_bar) {
    
    	if (current_user_can('manage_network'))
    
    	$admin_bar->add_menu( array(
    		'id'    => 'vvd-my-sites',
    		'title' => 'My Sites',
    		'href'  => admin_url('my-sites.php'),
    		'meta'  => array(
    			'title' => __('My Sites'),
    		),
    	));
    
    	$sites = wp_get_sites();
    	foreach ($sites as $site) {
    
    		$site_title = ( $site['blog_id'] == 1 ) ? "Main site" : "Blog";
    		$admin_bar->add_menu( array(
    			'id'    => 'vvd-network-sites-'.$site['blog_id'],
    			'parent' => 'vvd-my-sites',
    			'title' => $site_title,
    			'href'  => get_site_url($site['blog_id']),
    		));
    
    }
    	}
    add_action('admin_bar_menu', 'vvd_my_sites', 20);

    Best Regards,
    Vinod Dalvi

  • blogjunkie

    Found an alternative solution. This code will replace the site title with the domain name:

    
    /*
     * Change My Sites Menu Names to domain.com as the menu name
     */
    function change_site_names() {
    	global $wp_admin_bar;
    		$blavatar = '<div class="blavatar"></div>';
    	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
    			$menu_id  = 'blog-' . $blog->userblog_id;
    			$blogname = $blog->domain;
    		$wp_admin_bar->add_menu( array(
    			'parent' 	=> 'my-sites-list',
    			'id' 	=> $menu_id,
    			'title' 	=> $blavatar . $blogname,
    			'href' 	=> get_admin_url( $blog->userblog_id ) )
    		);
    	}
    }
    add_action( 'wp_before_admin_bar_render', 'change_site_names' );
    

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.