• Hy guys,
    I really hope you can help me.
    I need a button on my website that reditects users based on their username. For example if someones username is asdfg he should be redirect to domain.com/~asdfg.
    I know there is the plugin Peter’s Login Redirect, but that is not what I need, because I need to redirect users that are already logged in.

    Thank you very very much,
    Luca

Viewing 7 replies - 1 through 7 (of 7 total)
  • Yes, you can do this quite easily.
    You could put this code into a plugin, and activate it using a shortcode in either copy, or a widget.
    But I feel that a more natural arrangement would be to put it into your theme, make sure this is a child theme.
    creating a child theme https://codex.www.ads-software.com/Child_Themes

    Where do you need this button on your page ? Add it to the relevant part of your theme.

    Thread Starter plose2009bx

    (@plose2009bx)

    Hi and thank you for the reply,

    the problem is that I don’t have much experience with coding.
    Could you write a code for me to put in the page template of the theme?

    Thank you,
    Luca

    There are very likely things about this that won’t suit you, but it will be something like this:

    <?php
    	if ( is_user_logged_in() ) {
    		$user = wp_get_current_user();
    		echo '<div class="userButton"><a href="https://someWebSite/~'. $user->user_login . '"><img src="aButton.jpg"></a></div>';
    	}
    ?>
    Thread Starter plose2009bx

    (@plose2009bx)

    Thank you very much RossMitchell for the fast reply.

    Now I found a button code that I would like to modify:

    <div class="col-sm-3 clientarea-button">
    <a>" href="<?php echo $whmcs_url . 'dologin.php?email=' . $client_email . '&timestamp=' . $timestamp . '&hash=' . $hash . '&goto=' . urlencode($whmcs_subfolder . 'clientarea.php'); ?>">
    <span class="glyphicon glyphicon-globe"> </span>
    <h4><?php echo __('My Website', 'woocommerce-whmcs'); ?></h4>
    </a>
    </div>

    Could you please modify this code for me, so that it points to [username].wpbox.org/wp-admin, where [username] is the username of the logged in user.
    I don’t need anything like if ( is_user_logged_in(), because only logged in users see this button.

    Thank you very much,
    Luca

    There were some errors in the code too:

    <div class="col-sm-3 clientarea-button">
    <a href="https://siteName/~<?php echo wp_get_current_user()->user_login; ?>">
    <span class="glyphicon glyphicon-globe">&nbsp;</span>
    <h4><?php echo __('My Website', 'woocommerce-whmcs'); ?></h4>
    </a>
    </div>
    Thread Starter plose2009bx

    (@plose2009bx)

    Thank you very very much! Works perfect!
    One last favor. Could you please change the second line
    so that it points to https://username.sitename.com/wp-admin instead of https://sitename/~username

    Once more with feeling:

    <div class="col-sm-3 clientarea-button">
    <a href="https://<?php echo wp_get_current_user()->user_login; ?>.siteName.com/wp-admin">
    <span class="glyphicon glyphicon-globe">&nbsp;</span>
    <h4><?php echo __('My Website', 'woocommerce-whmcs'); ?></h4>
    </a>
    </div>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Redirect based on username’ is closed to new replies.