Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active November 20, 2025 12:03
Show Gist options
  • Select an option

  • Save yuriinalivaiko/079c952fbc79d6bbf784834b1871f570 to your computer and use it in GitHub Desktop.

Select an option

Save yuriinalivaiko/079c952fbc79d6bbf784834b1871f570 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Shortcode that displays the header section of the Ultimate Member profile.
<?php
/**
* Builds the profile header shortcode output.
*
* The supported attributes for the shortcode are 'form_id', 'user_id'.
* Example 1: [um_profile_header]
* Example 2: [um_profile_header form_id="7" user_id="1"]
* Example 3: [um_profile_header form_id="7" user_id="get_current_user_id"]
*
* @param array $atts {
* Attributes of the shortcode.
*
* @type int $form_id The profile form ID. The first profile form if blank.
* @type int|string $user_id The user ID. The page/post author if blank. May accept a function.
* }
* @param string $content Shortcode content.
*
* @return string|void HTML content to display the profile header.
*/
function um_profile_header_shortcode( $atts, $content ) {
$args = shortcode_atts(
array(
'form_id' => 0,
'user_id' => 0,
),
$atts
);
if ( empty( $args['form_id'] ) ) {
// Get the first profile form if the `form_id` attribute is empty.
$forms = get_posts(
array(
'fields' => 'ids',
'meta_key' => '_um_mode',
'meta_value' => 'profile',
'order' => 'ASC',
'post_type' => 'um_form',
)
);
$args['form_id'] = current( $forms );
}
if ( empty( $args['user_id'] ) ) {
// Get the author ID or current user ID if the `user_id` attribute is empty.
$args['user_id'] = is_singular() ? get_the_author_meta( 'ID' ) : um_profile_id();
} elseif ( ! is_numeric( $args['user_id'] ) && is_callable( $args['user_id'] ) ) {
// Get the user ID via a function if callable.
$args['user_id'] = $args['user_id']();
}
if ( empty( $args['form_id'] ) || empty( $args['user_id'] ) ) {
return;
}
$post_data = UM()->query()->post_data( $args['form_id'] );
if ( is_array( $post_data ) ) {
$args = array_merge( $args, $post_data );
}
$args = apply_filters( 'um_pre_args_setup', $args );
$args = apply_filters( 'um_shortcode_args_filter', $args );
if ( ! um_get_requested_user() ) {
um_set_requested_user( $args['user_id'] );
um_fetch_user( $args['user_id'] );
}
ob_start();
?>
<div class="um um-profile um-viewing <?php echo esc_attr( 'um-' . $args['form_id'] ); ?> um-profile-header-shortcode">
<div class="um-form" data-mode="profile">
<?php
do_action( 'um_profile_header_cover_area', $args );
do_action( 'um_profile_header', $args );
do_action( 'um_profile_navbar', $args );
?>
</div>
</div>
<?php
UM()->shortcodes()->dynamic_css( $args );
$content = ob_get_clean();
if ( um_get_requested_user() ) {
um_reset_user();
}
return $content;
}
add_shortcode( 'um_profile_header', 'um_profile_header_shortcode' );
@yuriinalivaiko

yuriinalivaiko commented Feb 10, 2023

Copy link
Copy Markdown
Author

Instruction

Install

Copy a code snippet above (without the opening php tag) and paste it to the functions.php file in the active theme directory.

Add shortcode

You can add the [um_profile_header] shortcode to the page/post content to display the page/post author like the header section of the Ultimate Member profile.

You can add this shortcode to the sidebar. The shortcode will be shown on the single (post) pages and will be hidden on archive (category) pages.

Attributes

Use optional attribute form_id to select a profile form you prefer. Default: the first profile form.
Use optional attribute user_id to display the profile header for the certain user. Default: author ID. May accept a function.

Examples

[um_profile_header]
[um_profile_header form_id="7"]
[um_profile_header form_id="7" user_id="1"]
[um_profile_header form_id="7" user_id="get_current_user_id"]

Screenshots

Image - Shortcode view in the post content.
01

Image - Shortcode view in the sidebar.
02

Related Gists

  • You can use this code snippet if you need to display the profile form without the profile header.

@demian1985

demian1985 commented Feb 21, 2023

Copy link
Copy Markdown

@yuriinalivaiko could you explain to me why I get no_cover class for the user's post while the user has submitted their profile cover?

See here the post: https://snipboard.io/P06SCI.jpg
See here the profile: https://snipboard.io/P06SCI.jpg

Edit: when I add a specific from ID it is showing. I think it's depending on this.

@yuriinalivaiko

Copy link
Copy Markdown
Author

@demian1985
Maybe you have multiple profile forms with different settings. The shortcode gets settings from the first fount profile form if there is no form_id attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment