function pac_da_custom_admin_bar_user_name() {
global $wp_admin_bar;
// Define the ID of the node representing the "My Account" section in the admin bar.
$node_id = 'my-account';
// Check if the specified node exists in the admin bar.
if ($wp_admin_bar->get_node($node_id)) {
// Get the current title of the "My Account" section.
$current_title = $wp_admin_bar->get_node($node_id)->title;
// Split the current title into an array based on the comma and space separator.
$newTitle = explode(", ", $current_title);
// Update the "My Account" section title with the second part of the split title if available,
// otherwise keep the current title.
$wp_admin_bar->add_node(array(
'id' => $node_id,
'title' => isset($newTitle) && isset($newTitle[1]) ? $newTitle[1] : $current_title,
));
}
}
// Hook the custom admin bar user name function to run before the admin bar is rendered.
add_action('wp_before_admin_bar_render', 'pac_da_custom_admin_bar_user_name');
This topic was modified 2 years ago by ankitbnl406