Mika MAtikainen

Apr 15, 2020 · 4 min read

How can I create a shortcode to display the user ID of any profile page in WordPress?

// Creating shortcode: [profile_owner_ID]
function wpsc_display_profile_owner_ID() {
    $user = uwp_get_displayed_user();
    
    // Check if $user is set and has an ID
    if ($user && isset($user->ID)) {
        return absint($user->ID);
    } else {
        return 'User ID not found.';
    }
}
add_shortcode('profile_owner_ID', 'wpsc_display_profile_owner_ID');

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This