How to link current logged-in user to their author page via URL (Beginner)

UPDATE

As per the comment, here is the updated solution.

Note: Before copy pasting, don’t forget to change somePrefix with any other prefix to avoid conflict with any other
shortcodes.

Step 1: Make sure you have this filter in functions.php (If not, copy paste it there)

add_filter('wp_nav_menu_items', 'do_shortcode');

Step 2: Use this snippet to return Author URL. Paste this in functions.php

add_shortcode( 'somePrefix_author_url', function() { 
    
    $author_link = get_author_posts_url( get_current_user_id() ); // original link
    $without_protocol = trim( str_replace( array( 'http://', 'https://' ), '', $author_link ), "https://wordpress.stackexchange.com/" );
    return  $without_protocol; // returns author link without protocol
    
});

Step 3: Go to Navigation Menu and add Custom Menu Link and use [somePrefix_author_url] in the URL field and ‘My personal page’ or something in the Name field.

Step 4: Test the link from the front-end if it works.

Reason for using link without protocol:

By default http/ without colon is appended to the shortcode for some reason after this update. This could be a bug or maybe not as this behavior can be intentional. Anyways, the above code is safe to use as WP will automatically append the protocol to the custom link in this case.


Yes, this will do the trick. For HTML link, instead of just the function that outputs the URL only, use this from your snippet:

    echo '<a href="' . esc_url(get_author_posts_url( wp_get_current_user()->ID )) .'">
      My personal page
    </a>';

It should output ‘My personal page’ text hyperlinked to the current user’s author page.

Additional Tip:
You can get the user object with this:

    $currentUser = wp_get_current_user();
    $currentUserID = $currentUser->ID;
    $userAuthorLink = get_author_posts_url($currentUserID);
    $userFirstName = $currentUser->first_name; 

// and so on 

Later in your code instead of repeating the call for same object with wp_get_current_user() and global $current_user get_currentuserinfo();, you can call the user object for once and use its properties as shared in the tip.

See WP_User Class for available object properties (ID, first_name, …) and methods (has_role() ..)