Archived topic
Is it possible to create a custom admin signature in the comment section?
6 replies · Started by Eugene on April 13, 2021
Lets say,
Admin: Billie Joe
In the comment section ONLY: Billie Joe is a good man.
Hi there,
Can you explain a bit more on how you want it laid out? A mockup image of how you want it to look like would give us a better idea on how to approach this.
Let us know. :)
Lets say, I logged in with nickname Billie Joe. This nickname will be exactly the same on Author's name (between featured image and post) and if i want to post something in the comment section.
Can i change or customize nickname in the comment section ONLY?
Ah I see.
This is pretty tricky to do but is definitely doable.
Consider this:
Create a custom field on the user profile form that will hold your preferred nickname on comment section only.
You can use ACF for this.
Example custom field setting:
https://share.getcloudapp.com/NQuwKXD2
IF you do this, a text field will appear on the user profile edit page as shown here:
https://share.getcloudapp.com/04uANZYA
You then add this PHP snippet:
add_filter('get_comment_author_link', 'add_custom_nickname');
function add_custom_nickname( $link ) {
global $comment;
$default_name_display = strip_tags( $link );
$custom_nickname = get_field('custom_comment_area_nickname','user_'.get_current_user_id());
if( !empty($custom_nickname) ){
$custom_name = $custom_nickname;
} elseif( empty($custom_nickname) ) {
$custom_name = $default_name_display;
}
if ( !empty( $comment->user_id ) && !empty( get_userdata( $comment->user_id )->ID ) ) {
$link = sprintf(
'<a href="%s" rel="external nofollow" class="url">%s</a>',
get_author_posts_url( $comment->user_id ),
$custom_name
);
}
return $link;
}
What this does is, it checks for the custom field you've created. If it's empty, it will use the default. If it's not empty, it will just whatever custom nickname was assigned to it on the field.
Thanks Elvin for your replay,
I am wondering if possible to implement this without any additional plugins installed? I tend to have fewer plugins as possible on my site.
Hi Eugene,
I'm afraid it's not possible without the plugin, otherwise, you'll have to write custom code for it which is like write a plugin by yourself.
I am wondering if possible to implement this without any additional plugins installed? I tend to have fewer plugins as possible on my site.
If you're worried about ACF being bloated, it's not. This plugin is pretty reputable. Lots of sites use it. It shouldn't affect the site performance significantly when enabled.
We'll need a plugin to store the custom nickname, unfortunately.