BuddyDev

Search

Adding div class around Show Xprofile Field Data in The Profile Header code

  • Participant
    Level: Guru
    Posts: 995
    calu on #36546

    Hi there, how do I add a div class around this code snippet for styling, I have tried different approaches, but I can’t make it work, can you help?

    /**
     * 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' );

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 21763
    Brajesh Singh on #36560

    Hi Carsten,
    Thank you for the question.
    Here is the code with awrapper div.

    
    /**
     * 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 "<div class='profile-job-info'>";
    		
    	    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;
    
    			}
    		}
    
    		echo '</div>';
    	}
    }
    
    add_action( 'bp_before_member_header_meta', 'yzc_add_xprofile_field_data_in_profile_header' );
    

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 995
    calu on #36567

    Hi Brajesh, thanks for bringing up the solution, appreciate it!

    Regards
    Carsten

  • Participant
    Level: Guru
    Posts: 995
    calu on #36594

    Hi Brajesh, for some reason the code with the wrapper div does not output any results?

    The field data has been changed according to the profile fields, what can be wrong?

    Regards

    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 21763
    Brajesh Singh on #36722

    Hi Carsten,
    I am sorry for the delayed reply.

    By mistake, I had made the code to show the data only if the “Age” was set. Please use this instead

    
    
    /**
     * 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() );
    
    	echo "<div class='profile-job-info'>";
    
    	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;
    
    		}
    
    		echo '</div>';
    	}
    }
    
    add_action( 'bp_before_member_header_meta', 'yzc_add_xprofile_field_data_in_profile_header' );
    

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved