Search
Close this search box.

How to display the user profile URL of a logged in user in WordPress

To display the user profile URL of a logged in user in WordPress, you can use the get_edit_user_link() function. This function returns the URL of the user’s profile page, where they can edit their profile information.

Here’s an example of how you can use this function to display the user profile URL for the currently logged in user:

<?php

// Display the user profile URL of a logged in user in WordPress
// More snippets at wpunplugged.com 

// Get the current user ID
$user_id = get_current_user_id();

// Get the user's profile URL
$profile_url = get_edit_user_link( $user_id );

// Check if the user is logged in
if ( $user_id ) {
    // Display the user's profile URL
    echo '<a href="' . esc_url( $profile_url ) . '">View your profile</a>';
} else {
    // Display a message if the user is not logged in
    echo 'You must be logged in to view your profile.';
}

?>

This code will display a link to the user’s profile page if they are logged in, or a message if they are not logged in.

Share this post

You might also like...

Comment

Your email address will not be published. Required fields are marked *