WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to add the language of every blog to the blogname inside the my-site-list inside the admin-bar.

The result should look like this: enter image description here

For adding the languages to to the site-name in (1) I use this code:

add_action('wp_before_admin_bar_render', 'add_language_to_blog_name');
function add_language_to_blog_name( $wp_admin_bar ) {

    global $wp_admin_bar;

    $wp_admin_bar->add_menu( array(
        'id'    => 'site-name',
        'title' => get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'language' ),
    ) );


How can I edit the blognames inside the my-site-list?

share|improve this question
up vote 0 down vote accepted

This is a little tricky, and I don't know if I got the best solution for this. However, it works.

The trick is, I use the same hook as you do, wp_before_admin_bar_render. In there I get all the elements, and check them if they have the parent my-sites-list.

If they do, I switch to the blog, get the language of the current blog, create the title and call restore_current_blog().

After that, I create a new admin bar item, containing all the original information but the new title, remove the old one and insert the new one right afterwards.


  • I could not find out by now if there is a way to get a blogs language without switching to it.
  • Maybe there is a filter for the generation of the admin bar menu items. It would be much better to filter those titles there than manipulating them afterwards.

The function

function f711_tweaked_admin_bar() {

    global $wp_admin_bar;
    $elements = $wp_admin_bar->get_nodes();
    foreach( $elements as $element ) {

        if ( $element->parent == 'my-sites-list' ) {

            // reduce the adminbar Id to the blog ID
            $idinteger = str_replace( 'blog-', '', $element->id );

            // Switch to the Blog, get the language option. If empty, it's English
            switch_to_blog( $idinteger );
                if ( get_option( 'WPLANG' ) != "" ) {
                    $language = get_option( 'WPLANG' );
                } else {
                    $language = 'en_EN';
                //set the new title for the Admin Menu
                $newtitle = $element->title . ' - ' . $language;

            // define new menu element
            $args = array(
                'title'     => $newtitle,
                'id'        => $element->id,
                'parent'    => $element->parent,
                'href'      => $element->href,
            // remove the old one
            $wp_admin_bar->remove_node( $element->id );
            // add the new one right afterwards.
            $wp_admin_bar->add_node( $args );



add_action( 'wp_before_admin_bar_render', 'f711_tweaked_admin_bar' ); 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.