WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Register/login with user name (6 posts)

  1. DrGizmondo
    Member
    Posted 4 years ago #

    Hi all, can some one please help me im wanting to add a register / login link to the top of my blog, once their logged it I would like this to change the users username along with a logout link. I have looked at the relivent Codex pages and found some of what I beed, but I dont know how to string all the php together so that it works, please can someone help me out - thanks.

  2. Josh Leuze
    Member
    Posted 4 years ago #

    Hi Doc, this shouldn't be too tough to pull off.

    The trick is that you need to check to see if the user is logged in. If they aren't, you serve them the standard "wp_register" and "wp_loginout".

    A non-logged in user should see this:

    Register | Log in

    If the user is logged in, you check the user info, display the name, and then rather than show the standard admin link with "wp_register", you make the user's name a link to the dashboard. And then you follow that up with "wp_loginout" again.

    A logged in user should see this:

    John Doe | Log out

    Check out the code for doing this:

    <?php if (!(current_user_can('level_0'))){ ?>
    
    		<?php wp_register('',' | '); ?><?php wp_loginout(); ?>
    
    <?php } else { ?>
    
    		<a href="<?php echo get_option('home'); ?>/wp-admin/"><?php global $user_login;
    
    		get_currentuserinfo();
    
    		echo $user_login;
    
    		?></a> | <?php wp_loginout(); ?>
    
    <?php }?>

    Here's more info on the "get_currentuserinfo" function. And here is some info on adding a login form to a theme that I used for the user-based conditional statements.

  3. Samuel B
    moderator
    Posted 4 years ago #

    <?php wp_register(); ?>
    		<?php wp_loginout(); ?>

    won't that work?

  4. DrGizmondo
    Member
    Posted 4 years ago #

    thanks jleuze your code works like a charm.

  5. Josh Leuze
    Member
    Posted 4 years ago #

    @samboll Yeah, that's usually all I use on my sites, But there have been a couple that had a lot of users where a login form right in the theme would be handy.

    @DrGizmondo No problem, happy to help!

  6. mdisch
    Member
    Posted 4 years ago #

    How do you redirect to a page after logging out using wp_loginout();?

Topic Closed

This topic has been closed to new replies.

About this Topic