Display user role under BuddyPress username on profile page

Hello,
URL: http://yourtechadvisors.com/members/yourtechadvisors/
I am using the following code in the file
/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/member-header.php

<span class="user-role">
<?php
$user = new WP_User( bp_displayed_user_id() );
echo $user->roles[0];
?>
</span>

I am wondering if there is a way to use this code with a function in functions.php so that when the plugin is updated, I don't have to keep coming back to change this file. If not, it will be fine, this ticket is more for looking towards convenience then fixing an issue.

Thanks, please let me know what the best solution would be here.