BuddyDev

Search

show Xprofile Field Data in The Profile Header, exclude own profile

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #32487

    Hi there, I’m using the following code to show Xprofile Field Data in The Profile Header.

    I want the code excluded from profiles own profile. The only way I know is to exclude the code from being displayed with css .myaccount But it’s not wrapped in a div so I have no class to attack. What is best, adding a div class, or exclude own profile in the code?

    Help with both solutions would be much appreciated, thanks!

    /**
     * Buddypress Show Xprofile Field Data in The Profile Header.
     */
     
    function yzc_add_xprofile_field_data_in_profile_header( $name ) 
    
    {
    	
    	$field_data = xprofile_get_field_data( 'Age', bp_displayed_user_id() );
    	if ( ! empty( $field_data ) ) {
    		echo '<br/><strong>Alder:</strong> ' . $field_data;
    	
    	$field_data = xprofile_get_field_data( 'From', bp_displayed_user_id() );
    	if ( ! empty( $field_data ) ) {
    		echo '  <br/> <strong>Fra:</strong> ' . $field_data;
    	
    	$field_data = xprofile_get_field_data( 'Job', bp_displayed_user_id() );
    	if ( ! empty( $field_data ) ) {
    		echo '<br/><strong>Job:</strong> ' . $field_data;
    			
    	}
    }
    } 
    }
    
    add_action( 'bp_before_member_header_meta', 'yzc_add_xprofile_field_data_in_profile_header' );
    
  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #32490

    Hi Carsten,
    Thank you for the question.

    You can use it like this.

    
    
    /**
     * Buddypress Show Xprofile Field Data in The Profile Header.
     */
    function yzc_add_xprofile_field_data_in_profile_header( $name ) {
    
    	if ( bp_is_my_profile() ) {
    		return;
    	}
    
    	$field_data = xprofile_get_field_data( 'Age', bp_displayed_user_id() );
    	if ( ! empty( $field_data ) ) {
    		echo '<br/><strong>Alder:</strong> ' . $field_data;
    
    		$field_data = xprofile_get_field_data( 'From', bp_displayed_user_id() );
    		if ( ! empty( $field_data ) ) {
    			echo '  <br/> <strong>Fra:</strong> ' . $field_data;
    
    			$field_data = xprofile_get_field_data( 'Job', bp_displayed_user_id() );
    			if ( ! empty( $field_data ) ) {
    				echo '<br/><strong>Job:</strong> ' . $field_data;
    
    			}
    		}
    	}
    }
    
    add_action( 'bp_before_member_header_meta', 'yzc_add_xprofile_field_data_in_profile_header' );
    

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #32499

    Hi Brajesh, thanks for adding this simple and elegant solution to the code, it works perfectly!

    Sorry for adding the topic twice 😉

    Regards
    Carsten

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #32500

    Resolved

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #32518

    You are welcome. No issues with duplicate topic.

    Regards
    Brajesh

The topic ‘show Xprofile Field Data in The Profile Header, exclude own profile’ is closed to new replies.

This topic is: not resolved