• Resolved bmcconach

    (@bmcconach)


    Hi there,

    I’m trying to find a way to display the Birthdate field with a “Birthdate” label when editing the field value, and an “Age” label when viewing the profile.

    Otherwise, “Birthdate: Jan 12 1934” when editing will show as “Birthdate: 85 years” with the “Check this if you want to show age instead of birthdate” option enabled.

    Ideally, when viewing the profile of a member, it should show “Age: 85 years”.

    Here’s an image of the profile field when editing:
    https://i.gyazo.com/1dba7df9d9ee7f8d39676acf35fe2ed8.png
    Here’s an image of the profile field when viewing:
    https://i.gyazo.com/e135f52816ac23e53ed3895920a285cd.png
    Here’s an image of what I’m trying to accomplish when viewing:
    https://i.gyazo.com/c83ae81427e41da9ce66a7d9ffa4820a.png

    Essentially, when the “Check this if you want to show age instead of birthdate” option enabled” has been checked, the profile field should show “Age” instead of “Birthdate”.

    My apologies for the poor explanation, but I do hope someone can shed light on how this can be accomplished. Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Brajesh Singh

    (@sbrajesh)

    Hi,
    Thank you for the post.

    The plugin does not deal with field labels. It only deals with the values.

    You are seeing theI do understand your need though. The problem is in the plugin we can not decide the edit/view context out of the box.

    There is a fielter

    
    bp_get_the_profile_field_name
    

    which can be used to show the different labels.
    A code like this should work

    
    
    add_filter( 'bp_get_the_profile_field_name', function ( $label ) {
    	global $field;
    	if ( ! $field || $field->type !== 'birthdate' ) {
    		return $label;
    	}
    
    	if ( bp_is_register_page() || is_admin() || bp_is_user_profile_edit() ) {
    		return $label;
    	}
    
    	return "Age";
    
    } );
    
    

    Regards
    Brajesh

    Thread Starter bmcconach

    (@bmcconach)

    Brajesh,

    Thank you so very much for your assistance! The code you provided gave me exactly the desired effect I was hoping to achieve. I couldn’t be more happy! Major kudos for an excellent plugin and support!

    Best regards!

    Plugin Author Brajesh Singh

    (@sbrajesh)

    Thank you ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Birthdate/Age Text Display’ is closed to new replies.