Adding PHP in the menu

Add to your functions file and use wp_nav_menu_items

add_filter('wp_nav_menu_items','wpsites_add_avatar_to_nav', 10, 2);
function wpsites_add_avatar_to_nav( $items, $args ) {
    if( $args->theme_location == 'primary' )
    return $items;    

    $dude = get_avatar( get_current_user_id(), 48 );

    if (is_user_logged_in()) : 
    echo'<li class="your-custom-class right">' . $dude . '</li>';
    endif;

    return $items;
}

Might need to use output buffering.

Some work is required on your behalf to get your code working with this filter. You will need to change the class depending on which theme you’re using.