Community Forums › Forums › Archived Forums › General Discussion › How to sync up the Screen Name throughout the website
- This topic has 3 replies, 2 voices, and was last updated 7 years ago by Victor Font.
-
AuthorPosts
-
March 21, 2017 at 9:20 pm #203615riseUpMember
Hello,
For my website, http://www.ymphony.com, there is a concept of a Screen Name. The Screen Name is displayed at the top of each post on the homepage. It says "By <Screen Name>."
However, when you enter a post and scroll down, you will notice a comment section like here: http://ymphony.com/work-needed/
But notice that the names displayed in the comments section is different than the Screen Name displayed from the homepage's Screen Name at the top of each post.
Can somebody advise on how to sync up the name displayed in the comment section to be the same as list on the homepage's Screen Name?
It just makes sense to have the names be the same since the name is quite important from an identity standpoint. Thank you!
http://www.ymphony.comMarch 22, 2017 at 5:45 am #203642Victor FontModeratorComments use the comment author name. Genesis calls the WordPress function get_comment_author_link() to retrieve the comment author name. https://developer.wordpress.org/reference/functions/get_comment_author_link/. The WordPress function has a filter you can use to change the output. If you look at this function's source code, the last line is:
return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
This means you can write your own function to return the screen name by using an add_filter in functions.php.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?March 22, 2017 at 8:42 pm #203689riseUpMemberHi Victor,
So, I'm been trying some code based upon your recommendation, and this is what I attempted, but this does not work. I've tried some variations of this:
function get_comment_author( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( empty($comment->comment_author) ) {
if (!empty($comment->user_id)){
$user=get_userdata($comment->user_id);
$author=$user->user_login;
} else {
$author = __('Anonymous');
}
} else {
$author = $comment->comment_author;
}
return apply_filters('get_comment_author', $author);
}Can you assist in the above set of code by any chance?
March 23, 2017 at 7:07 am #203707Victor FontModeratorThat's not the way you use a filter, but it doesn't matter. I was looking at the non-HTML5 code and instructed you incorrectly. That filter is not going to work for you. In fact, the Genesis HTML5 code does not have a filter for changing the author. This is going to be a lot of work, but you will have to write your own comment callback function. The process is not going to be easy.
1. Copy the genesis_html5_comment_callback() function from genesis/lib/structure/comment.php and paste it into the child theme's functions.php.
2. Rename the copied function so there's no conflict with the Genesis function
3. Modify the author variable to retrieve your screen name
4. Add the following code to functions.php so your new function is called.
5. Change "my_renamed_function_from_step_2" to whatever you named the new function is step 2.add_filter( 'genesis_comment_list_args', 'my_comment_args' ); function my_comment_args($args) { $args['callback'] = "my_renamed_function_from_step_2"; return $args; }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet? -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.