Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/7c38169810fc199502ec6b11b0dc4e11 to your computer and use it in GitHub Desktop.
Save andrewlimaza/7c38169810fc199502ec6b11b0dc4e11 to your computer and use it in GitHub Desktop.
Change the display name for Member Directory and Profile Pages Add On
<?php
/**
* Replace a user's display name on directory and profile page with their full name.
* This requires the latest version (1.0+) of the Member Directory and Profile Pages Add On - https://www.paidmembershipspro.com/add-ons/member-directory/
*
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_member_directory_change_display_name( $display_name, $user ) {
$first_name = isset( $user->first_name ) ? $user->first_name : get_user_meta( $user->ID, 'first_name', true );
$last_name = isset( $user->last_name ) ? $user->last_name : get_user_meta( $user->ID, 'last_name', true );
if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
$display_name = $first_name . ' ' . $last_name;
}
return $display_name;
}
add_filter( 'pmpro_member_directory_display_name', 'my_pmpro_member_directory_change_display_name', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment