How to add user avatar to leaderboard?
-
How to add user avatar to leaderboard? I use Ultimate Member!
-
Hello @ranbac ,
Hope you are doing well.
Here is the documentation link below. You will see it there.
Let me know if you have any question.
Thanks & Regards,
WP Experts Support Team
I added two code . Not worked.
Column Headers
/**
- Add Custom Leaderboard Column
- @since 1.0
- @version 1.0
*/
function mycred_pro_bp_leaderboard_columns( $columns ) { $columns[‘avatar’] = ‘Avatar’; return $columns;
}
add_filter( ‘mycred_bp_leaderboard_columns’, ‘mycred_pro_bp_leaderboard_columns’ );Column Content
/**
- Avatar Leaderboard Column
- @since 1.0
- @version 1.0
*/
function mycred_pro_bp_leaderboard_avatar_column( $content, $row, $group_id, $point_type ) { return get_avatar( $row->user_id, 64 );
}
add_filter( ‘mycred_bp_leaderboard_avatar_column’, ‘mycred_pro_bp_leaderboard_avatar_column’, 10, 4 );Hello @ranbac ,
Try using the below code snippet:
add_filter( ‘mycred_ranking_row’, ‘mycredpro_add_avatars_to_leaderboard’, 10, 4 );
function mycredpro_add_avatars_to_leaderboard( $layout, $template, $user, $position ) {
if ( isset( $user->ID ) )
$user_id = $user->ID;elseif ( isset( $user[‘ID’] ) )
$user_id = $user[‘ID’];else return $layout;
$avatar = get_avatar( $user_id, 32 );
return str_replace( ‘%avatar%’, $avatar, $layout );
}
We encountered an error activating your snippet, please check the syntax and try again. Error message:?
Undefined constant ‘mycred_ranking_row’
Try this
/**
- Add Avatars To Leaderboard
- @since 1.0
- @version 1.0 */ add_filter( ‘mycred_ranking_row’, ‘mycredpro_add_avatars_to_leaderboard’, 10, 4 ); function mycredpro_add_avatars_to_leaderboard( $layout, $template, $user, $position ) {? if ( isset( $user->ID ) )
$user_id = $user->ID;
elseif ( isset( $user[‘ID’] ) )$user_id = $user['ID'];
else return $layout;? avatar = get_avatar( $user_id, 32 );? return str_replace( ‘%avatar%’, $avatar, $layout );
}
We encountered an error activating your snippet, please check the syntax and try again. Error message:?
syntax error, unexpected token =
Hello @ranbac ,
Please try below code.
add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 ); function my_custom_ranking_rows( $layout, $template, $row, $position ) { $avatar = get_avatar( $row['ID'], 32 ); return str_replace( '%avatar%', $avatar, $layout ); } <table> <thead> <tr> <th>Position</th> <th>Name</th> <th>Points</th> <th>Avatar</th> </tr> </thead> <tbody> [mycred_leaderboard wrap=""] <tr> <td>%position%</td> <td>%display_name%</td> <td>%cred_f%</td> <td>%avatar%</td> </tr> [/mycred_leaderboard] </tbody> </table>
Below is the attached screenshot for reference : Screenshot
Let me know if you have any question.
Thanks
- This reply was modified 1 year, 7 months ago by Daniyal Raza.
It worked. Beautiful! You should insert this to 2.1 release version.
PHP code
add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 ); function my_custom_ranking_rows( $layout, $template, $row, $position ) { $avatar = get_avatar( $row['ID'], 32 ); return str_replace( '%avatar%', $avatar, $layout ); }
HTML code
<table> <thead> <tr> <th>Position</th> <th>Name</th> <th>Points</th> <th>Avatar</th> </tr> </thead> <tbody> [mycred_leaderboard wrap=""] <tr> <td>%position%</td> <td>%display_name%</td> <td>%cred_f%</td> <td>%avatar%</td> </tr> [/mycred_leaderboard] </tbody> </table>
- This reply was modified 1 year, 7 months ago by Nguy?n Qu?c Hùng.
Hello @ranbac ,
Thanks for the update.
We will discuss it with our technical team. If they approve it then we will add it in myCred release 2.1
Please give your review/feedback to our plugin and support on Mycred.
Thanks
- This reply was modified 1 year, 7 months ago by Daniyal Raza.
- This reply was modified 1 year, 7 months ago by Daniyal Raza.
- The topic ‘How to add user avatar to leaderboard?’ is closed to new replies.