Notifications
Clear all

Remove link from mentioned username in comment

6 Posts
3 Users
0 Reactions
1,737 Views
Posts: 14
Customer
Topic starter
(@devin)
Member
Joined: 8 years ago

Hi wpDiscuz Team,

Can you tell me how I can remove the link from the username that appears when a user is mentioned in a comment? Here's an example on my page  https://countryguitaronline.com/worried-blues-guitar-lesson/#comment-4017126

The reason I'd like to remove the link is because all of the members on my website are Subscribers and not Editors or Admin so they don't have any posts. When I click the link of the wpDiscuz mentioned user in the comment, it goes to a blank page with zero posts by that Subscriber.

Thanks for your help! I'm still really loving the plugin.

Devin

5 Replies
Astghik
Posts: 6149
Admin
(@astgh)
Illustrious Member
Joined: 7 years ago

Hi @devin,

I'm sorry, but there is no option for this purpose. You should add this js code in your current active theme's js file, it'll remove the link from the mentioned username:

jQuery.each(jQuery('.hint'), function () {
var txt = jQuery(this).html();
var cls = jQuery(this).attr('class');
var data = jQuery(this).attr('data-ucm_user_id');
jQuery(this).replaceWith(jQuery('<span></span>').attr('class', cls).attr('data-ucm_user_id', data).html(txt))
});
Reply
Posts: 8
(@davehamilton)
Active Member
Joined: 6 years ago

Is this still the best/only solution here? We were hoping that maybe a hook had been added so we could write an override function to keep it from ever being passed in the HTML in the first place.

Thanks!

Reply
3 Replies
Astghik
Admin
(@astgh)
Joined: 7 years ago

Illustrious Member
Posts: 6149

yes @davehamilton, you'll need to use this solution. No other we can provide you. 

 

Reply
(@davehamilton)
Joined: 6 years ago

Active Member
Posts: 8

@astghik Thanks for the note. We actually spent some time last night coding and came up with an even better workaround. 

The problem with the aforementioned JavaScript override is that it still puts the href link in the HTML source, and since the JavaScript doesn't hide it from Google we were still were getting dinged for broken links to these non-existent author pages.

To solve this, we created a custom function in our custom plugin that hooks into the Wordpress the_author_link() function and clears it from there.

Works perfectly, and completely eliminates this mess for us. You might need to modify this based upon your custom plugin's functionality as it relates to authors, but edit_posts was a perfect "litmus test" for us here.

function our_custom_author_link( $link, $author_id, $author_nicename ) {

if ( !user_can( $author_id, 'edit_posts' ) ) {
return '';
}
// Otherwise, return $link unmodified
return $link;
}
add_filter( 'author_link', 'our_custom_author_link', 10 , 3 );
Reply
Astghik
Admin
(@astgh)
Joined: 7 years ago

Illustrious Member
Posts: 6149

Thank you @davehamilton!

Yes, we'll make those changes in the plugin core. 

Reply
Share:
Scroll to top