• Works as described, compatible with wp-members plugin shortcode.

    I am new to WordPress and I am surprised that we can’t use shortcode in menu labels. I found a lot of methods based on a modification of the theme to display a different menu based on the connection status. Not user friendly + can be lost if the theme is modified.

    Thank you for this!

Viewing 1 replies (of 1 total)
  • Thread Starter thenemal

    (@thenemal)

    Bonus: mod shortcode to display “Sign in” when the user is not connected:

    add_shortcode( ‘current-username’ , ‘username_on_menu’ );

    function username_on_menu(){

    $user = wp_get_current_user();
    $HTMLEntityHexadecimal = ‘👤’; // bust in silhouette https://graphemica.com/%F0%9F%91%A4

    if (empty($user->display_name)) {
    $username_on_menu_label = “Sign In”;
    } else {
    $username_on_menu_label = html_entity_decode($HTMLEntityHexadecimal).” “.$user->display_name;
    }

    return $username_on_menu_label;
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Exactly what I was looking for!’ is closed to new replies.