• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.1 Strip hyperlink from username

Mike Edge

Formerly Da Bookie Mon
#1
I can't find a way to do it. I want to strip the hyperlink from the poster's username making the username not clickable.
 

Mike Edge

Formerly Da Bookie Mon
#3
Unless I can get the link to work correctly on the member card, I'd like to disable it site wide as I want to use facebook profiles as the site profile. On the membercard for the profile page link if i use facebook.com/{$fbUser.username} it links to your own account not the poster and using facebook.com/{$user} nothing happens.
 

Chris D

XenForo developer
Staff member
#4
For the most part, this can be achieved by editing the template helper...

So XenForo usually produces a username via two ways:

1) <xen:username tags
2) {xen:helper username

The <xen:username tag, interestingly enough, ultimately just calls the helper. So if you edit that helper, you pretty much affect almost everywhere a username appears.

e.g. XenForo/Template/Helper/Core.php. Line 1663:
PHP:
return "<a{$href} class=\"username{$class}\"{$attribs}>{$username}</a>";
Change it to:

PHP:
return "<span class=\"username{$class}\"{$attribs}>{$username}</span>";
It will work for everywhere that uses the default tag/helper. This doesn't necessarily include everything. You will have to use a bit of leg work to discover which links aren't changed by this helper edit, but that should be quite a simple job for the most part.

(Note, the line number above are correct as of XenForo 1.2 Beta 3)

EDIT: You would need to look at modifying the avatar helper too as that links through to the profile. But it should be a similar process.
 

Mike Edge

Formerly Da Bookie Mon
#5
Thanks @Chris Deeming ! One other question. How can I get this to work? Anything I try, if I include the "{ }" the link is only facebook.com and if I only use $username it is facebook.com/$username not the username. I am forcing the FB username at sign up using $fbUser, so the URL will always be correct
 

Chris D

XenForo developer
Staff member
#6
This seems to work for me:

PHP:
return "<a href=\"http://facebook.com/{$username}\" class=\"{$class}\"{$attribs}>{$username}</a>";
As I said in my edit, you would need to ensure you look at the helperAvatarHtml function too and modify that in a similar way. Note, I removed the username class (that's what triggers the member card JS).

As for defining it in a normal template:

<a href="http://www.facebook.com/{$user.username}">{$user.username}</a>
 

Mike Edge

Formerly Da Bookie Mon
#9
This seems to work for me:

PHP:
return "<a href=\"http://facebook.com/{$username}\" class=\"{$class}\"{$attribs}>{$username}</a>";
This worked perfect! I added a target to it so they don't leave my site via clicking the link

PHP:
return "<a href=\"https://facebook.com/{$username}\" target=\"new\" class=\"{$class}\"{$attribs}>{$username}</a>";
 

Mike Edge

Formerly Da Bookie Mon
#11
Revisiting for some code changes. Maybe you have a solution @Chris Deeming.

So instead of forcing FB username as I orginally planned, I decided to allow them to choose their own name and use auth id to link to them on facebook

So I changed the code to

Code:
return "<a href=\"https://facebook.com/{$user['facebook_auth_id']}\" target=\"new\" class=\"{$class}\"{$attribs}>{$username}</a>";
and it works in message info.. But in threads. if you goto https://www.blizzardhq.com/forums/main-forum.2/ the username link is only facebook.com
 

Chris D

XenForo developer
Staff member
#12
This can happen.

More than likely the fetch thread query doesn't join onto the xf_user_profile table which is where the facebook_auth_id is kept.
 

Mike Edge

Formerly Da Bookie Mon
#13
Is there a way to make the username unlinkable there yet clickable in the message info? Or will I need to use <span> instead and just make the avatar the link?