Q:

php-wordpress: cannot seem to append variable to href url

In following several tutorials on this, I am trying to append a php variable to a url within a < a> tags but am running into alot of trouble:
<?php
$fb='mike.jones';

if($fb) {
echo '<a href="http://facebook.com/' . $fb . '">Facebook</a>';
}
?>

Rather than just echoing "Facebook" and linking to http://facebook.com/mike.jones, it outputs: mike.jones>Facebook on the front and mike.jones is a hyperlink to www.facebook.com/<a. The syntax have been matched to the sample codes exactly. What is happening here?
I'm using php 7.2.15.
edit: here is one of the examples I've tried following:
https://wisdmlabs.com/blog/add-social-media-links-buddypress-profiles/

A:

If you are using WordPress and editing a page/post, php code will not be executed correctly because it is usually trimmed and formatted before being saved to the database. You should probably look into a plug-in that allows for PHP code, like Insert PHP Code Snippet which will allow you to add shortcode to your pages/posts to execute your PHP.
edit:
try using the following in your buddypress.php file instead of what you had shared with me:
function wdm_add_social_icons() {
  $user_id = $bp->displayed_user->id; // get BP user id
  $fb_page = xprofile_get_field_data('Facebook Profile', $user_id); // get data for user profile field
  if ($fb_page) {
    echo '<a href="https://facebook.com/' . $fb_page . '">FACEBOOK</a>';
  }
}
add_filter('bp_profile_header_meta', 'wdm_add_social_icons');

I would also clear your browser cache just to be safe.

