• Resolved themehelps

    (@themehelps)


    I am trying to display a member’s name on a page by using a shortcode.

    This shortcode isn’t working: [um_user meta_key=”first_name”]

    Is there a specific shortcode for Ultimate Member, or just [usermeta field=”first_name”]

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @themehelps – You can use this code snippet to enable the shortcode:

    /**
     * Returns a user meta value
     * Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
     * meta_key is the field name that you've set in the UM form builder
     * You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
     */
    function um_user_shortcode( $atts ) {
    	$atts = extract( shortcode_atts( array(
    		'user_id' => get_current_user_id(),
    		'meta_key' => '',
    	), $atts ) );
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = get_current_user_id(); 
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
     
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @themehelps

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards,

    Hello,

    Your snippet does not seem to work or I did something wrong,
    I put it in the functions.php and it still display nothing for all those shortcodes :

    [um_user meta_key=”name”] [um_user meta_key=”first-name”]

    Thank you!

    Edit : it works with : [um_user meta_key=”first_name”] !

    • This reply was modified 4 years, 5 months ago by eloysito.
    • This reply was modified 4 years, 5 months ago by eloysito.
    • This reply was modified 4 years, 5 months ago by eloysito.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode to Display User Meta Data (i.e. First Name)’ is closed to new replies.