Codex / mycred/log / Filters / mycred_ranking_row


  1. Description
  2. Used By
  3. Parameters
  4. Examples


This filter allows you to customize what is shown on each row in the leaderboard. You can use this to adjust layout by inserting custom HTML elements or by adding in custom details like a users avatar.

Important! Remember that this is a filter so you must always return a result!

Used By

  • Function: mycred_render_shortcode_leaderboard()


  • layout (string)
    The leaderboard row content. This is where template tags would be inserted.
  • template (string)
    The template either sent via the shortcode or set via preferences.
  • row (object)
    The database row currently being parsed. The user fields that were requested in the db query are included here. Default user fields:
  • ID The users ID.
  • user_login The users login (username).
  • user_email The users email address.
  • user_nicename The users nicename (if used).
  • display_name The users display name.
  • user_url The users set website URL.
  • cred The balance / credit sum.


  • position (int)
    The users position in the leaderboard.



Example 1: Add the custom template tag %avatar% allowing us to show each users avatar.

add_filter( 'mycred_ranking_row', 'mycredpro_rankings_row_avatar', 10, 4 );
function mycredpro_rankings_row_avatar( $layout, $template, $user, $position ) {

	if ( isset( $user->ID ) )
		$user_id = $user->ID;
	elseif ( isset( $user['ID'] ) )
		$user_id = $user['ID'];
		return $layout;

	$avatar = get_avatar( $user_id, 32 );
	return str_replace( '%avatar%', $avatar, $layout );


Example 2: Add a custom template tag that returns a user meta detail.

add_filter( 'mycred_ranking_row', 'mycredpro_rankings_row_meta', 10, 4 );
function mycredpro_rankings_row_meta( $layout, $template, $row, $position ) {

	if ( isset( $user->ID ) )
		$user_id = $user->ID;
	elseif ( isset( $user['ID'] ) )
		$user_id = $user['ID'];
		return $layout;

	$meta = get_user_meta( $user_id, 'meta_key', true );
	return str_replace( '%meta%', $meta, $layout );


Last edited October 10, 2016