Created
July 17, 2015 16:38
-
-
Save Zodiac1978/00141c991a62165e5741 to your computer and use it in GitHub Desktop.
Add language to multisite description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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' ), | |
) ); | |
} | |
add_action( 'wp_before_admin_bar_render', 'f711_tweaked_admin_bar' ); | |
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; | |
restore_current_blog(); | |
// 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 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment