I need a little help with what I believe would be PHP.


Depending on the username of the person logged in, I would like to create a URL that redirects a user to the aforementioned page. To do this, username needs to be replaced with their logged in username.

Is there an easy way to do this?


WordPress has several functions for getting user information, for example the following ones:


You can use wp_get_current_user()
This should do the trick:

$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
    wp_redirect( 'http://www.domain.com/author/'.$current_user->user_login.'/achievements/');  
} else {
    echo 'You have no business being here';

Also see the wp_get_current_user() documentation.

If you run in a:Warning: Cannot modify header information - headers already sent by

Add this to your functions.php:

add_action('init', 'do_output_buffer');
function do_output_buffer() {
  • The »logged-in»-check should be done via is_user_logged_in – Nicolai Apr 13 '15 at 11:59
  • Yes I agree. I changed my answer – Interactive Apr 13 '15 at 12:01
  • Note that output buffering rarely is needed, just do your redirect early enough, so before the header has been send. @JimFender – Nicolai Apr 13 '15 at 12:26

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.