The wordpress admin bar has a 'Site Name' section, that when clicked takes you to the dashboard if you're on the front end, or vice versa. The sitename code for the admin bar can be found in wp-includes/admin-bar.php and i'd modified a section to have it display 'Visit $title Site' or 'Visit $title dashboard' instead of just '$title' in the sitename section of the admin bar. However, I wanted the new text to show a shortened form of $title instead. Say, 'Tech' for a network site named 'Technology', thus resulting in 'Visit Tech dashboard' or 'Visit tech site' on the admin bar. I had coded a simple if-loop that would assign a short title based on the blog id.
//To rename admin bar's main title
function rename_dashboard_sitename() {
global $current_site, $wp_admin_bar;
if ($current_site->id == 1) {
$title=('Tech');}
elseif ($current_site->id == 2) {
$title=('IT');}
elseif ($current_site->id == 1) {
$title=('Info');}
elseif ($current_site->id == 7) {
$title=('Ads');}
elseif ($current_site->id == 5) {
$title=('Mkt');}
// Main Title
$wp_admin_bar->add_menu( array(
'id' => 'site-name',
'title' => is_admin() ? ('Visit '.$title.' Site') : ( 'Visit '.$title.' Dashboard' ),
'href' => is_admin() ? home_url( '/' ) : admin_url(),
) );
}
add_filter('wp_before_admin_bar_render', 'rename_dashboard_sitename');
However, while the code works to the effect that the text changes to 'Visit XXXX dashboard', it stays constant for all the network sites after that. the $title variable does not change to a new value in each new network site as it is supposed to by checking the site ID. Is there something wrong in the loop? Is there any reason the $title variable does not change from site to site? Is it not being called repeatedly? I have noticed that generally, only the last $title is used for all sites, so perhaps it's skipping all the other options and fixating on only the last one? I'm fairly new to PHP, so I apologize if the error is an obvious one.