Q: Wordpress - change wp_redirect url to dynamic link I have the following code that checks if a user is logged in and then redirects them to a particular static page - 
add_action('wp', 'add_login_check');
function add_login_check()
{
    if ( is_user_logged_in() && is_page( [153] ) ) {
        wp_redirect('https://my.thinkingmachine.co/vallis');
        exit;
    }
}

I want to change it so that instead of going to "https://my.thinkingmachine.co/vallis" they are directed to a dynamic url containing their user name, like this - 
  $username = $user->user_login;
  return ( '//my.thinkingmachine.co/' . $username . '/' );

How do I change the code so that it redirects to this dynamic url instead?
I tried this but it doesn't work - 
add_action('wp', 'add_login_check');
function add_login_check()
{
    if ( is_user_logged_in() && is_page( [153] ) ) {
        $username = $user->user_login;
      return ( '//my.thinkingmachine.co/' . $username . '/' );
        exit;
    }
}

Thanks
The whole code is - 
add_action('wp', 'add_login_check');
function add_login_check()
{
    if ( is_user_logged_in() && is_page( [153] ) ) {
        $username = $user->user_login;
        wp_redirect("https://my.thinkingmachine.co/{$username}");
        exit;
    }
}

add_action('wp', 'add_not_login_check');
function add_not_login_check()
{
    if ( !is_user_logged_in() && !is_page( [153] ) ) {
        wp_redirect('https://my.thinkingmachine.co/');
        exit;
    }
}


A: Presuming that the username is correctly get with this line of code:
$username = $user->user_login;

You can use this code:
function add_login_check()
{
    if ( is_user_logged_in() && is_page( [153] ) ) {
        $username = $user->user_login;
        wp_redirect("https://my.thinkingmachine.co/{$username}");
        exit;
    }
}

If you want to use a PHP variable inside a string, you have to use double quotes for the string and single braces around the variable.

A: Try code below:
function add_login_check() {
    if ( is_user_logged_in() && is_page( [153] ) ) {
        $username = wp_get_current_user()->user_login;
        $url = 'https://my.thinkingmachine.co/'. $username . '/';
        wp_redirect($url);
        exit;
    }
}
add_action('wp', 'add_login_check');

Hope help you.
