I used the following code to replace “Howdy” in the admin bar. This is lovely. However, when I view the site while logged in, the word Howdy reappears. As long as I’m viewing the dashboard, no howdy. When I am viewing the site, howdy.

//* Change the Dashboard Welcome Message

add_filter('gettext', 'change_howdy', 10, 3);

function change_howdy($translated, $text, $domain) {

    if (!is_admin() || 'default' != $domain)
    return $translated;

    if (false !== strpos($translated, 'Howdy'))
    return str_replace('Howdy', 'Explore the Possibilities', $translated);

    return $translated;

}

Anyone know how I make that change apply to both views of the admin bar?

1 Answer
1

I see a couple of problems here.

This line

 if (!is_admin() || 'default' != $domain)
    return $translated;

returns the Howdy right back unchanged if is_admin is false – which it is if you’re not in the dashboard.

Also, you’re running your filter callback on gettext. This means it will be run every time some internationalized content is used, which is very inefficient. You’d be better off using a more appropriate filter, like below.

function change_howdy( $wp_admin_bar ) {
    $my_account = $wp_admin_bar->get_node( 'my-account' );
    $new_title   = str_replace( 'Howdy', 'Explore the Possibilities', $my_account->title );
    $wp_admin_bar->add_node( array(
        'id'    => 'my-account',
        'title' => $new_title,
    ) );
}

add_filter( 'admin_bar_menu', 'change_howdy', 25 );

Leave a Reply

Your email address will not be published. Required fields are marked *