Skip to content

Instantly share code, notes, and snippets.

@dcorto
Last active August 29, 2015 14:09
Show Gist options
  • Save dcorto/35727fd1b66842011dae to your computer and use it in GitHub Desktop.
Save dcorto/35727fd1b66842011dae to your computer and use it in GitHub Desktop.
Wordpress Multisite Custom Sites Name by Lang
<?php
/*
Theme functions.php
*/
function change_site_names() {
global $wp_admin_bar;
if ( function_exists('is_multisite') && is_multisite() ) {
foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
$menu_id = 'blog-' . $blog->userblog_id;
$blogname = $blog->domain; //default
if($blog->userblog_id == 1){
$blogname = "Español";
}
else if($blog->userblog_id == 2){
$blogname = "Català";
}
else if($blog->userblog_id == 3){
$blogname = "English";
}
else if($blog->userblog_id == 4){
$blogname = "Français";
}
$wp_admin_bar->add_menu( array(
'parent' => 'my-sites-list',
'id' => $menu_id,
'title' => $blogname,
'href' => get_admin_url( $blog->userblog_id ) )
);
}
//Put current lang on the name of the site at wp admin bar
if ( !is_network_admin() && ! is_user_admin() ) {
$blogname = get_bloginfo('name');
$langCode = get_bloginfo('language');
$langArr = array("es-ES" => "Español", "ca" => "Català", "en-US" => "English", "fr-FR" => "Français");
if(isset($langArr[$langCode])){
$lang = $langArr[$langCode];
}
else{
$lang = "";
}
if ( empty( $blogname ) ){
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
}
$title = wp_html_excerpt( $blogname, 40, '&hellip;' );
$wp_admin_bar->add_menu( array(
'id' => "site-name",
'title' => $title." - ".$lang,
)
);
}
}
}
add_action( 'wp_before_admin_bar_render', 'change_site_names' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment