Last active
August 29, 2015 14:09
-
-
Save dcorto/35727fd1b66842011dae to your computer and use it in GitHub Desktop.
Wordpress Multisite Custom Sites Name by Lang
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 | |
/* | |
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, '…' ); | |
$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