0

I am currently trying to get the current username to add it to the url. The user should be able to navigate to his own dashboard wich is located under domain.com/username. Is there a way to retrieve the username and add it as variable to the url?

Thank you!

0

You can only do that if the user is logged in (otherwise there is no "current" user). Depending on what your specific use case is, it would be something like this:

if ( is_user_logged_in() ) {

    global $current_user;
    $current_user = wp_get_current_user();

    // get the username:
    $username = $current_user->user_login;

    // set up the URL:
    $url = home_url( $username );
}

Here's the documentation on the core WP functions I used above:

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.