I have several author page like


I want to create a dynamic url like


How to create this.

  • Can you provide more details? Currently, it is not clear to me what is going on with this dynamic link.
    – nmr
    Aug 3, 2019 at 15:27
  • @nmr I want to create an author page link in navigation menu bar where the logged in user will get to see all his post. The author page link is in this format mysite.com/author/{logged_in_username} .I want to pass the username in the url
    – user172955
    Aug 3, 2019 at 15:32

1 Answer 1


First, you should check if the user is logged in - use is_user_logged_in().
Next step is to get ID of current user with get_current_user_id().
Next, get the URL for the author with the given ID using get_author_posts_url().
The last step is to display the button with the link.

if ( is_user_logged_in() )
    $uid = get_current_user_id();
    $link = get_author_posts_url( $uid );
    printf( '<div><a href="%s">My posts</a></div>', $link );

You can insert such a code in the header.php file or add it as a function to functions.php file and call this function in the header.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.