WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding a login/registration bar at the top? (2 posts)

  1. jmlares
    Member
    Posted 6 years ago #

    So I have my blog set up and everything,

    http://www.gregjames.org/

    Now I want to add a little login thing at the top, some like bbPress's login, but I want it to say:

    -------------------------------------------------------------------
    Hello there, Guest! Login: [________] Password: [________] | Register
    -------------------------------------------------------------------

    How would that be accomplished?

  2. scribblerguy
    Member
    Posted 6 years ago #

    There's a plugin or two with login box widgets (see the Mini-Meta Widget plugin). Borrowing the code from one of them and modifying that would probably be the simplest trick.

    If you want to do this from scratch, then the actual code shouldn't be that difficult. It's mostly setting up a simple if-else statement:

    <?php if (!is_user_logged_in()) {
    // "Hello there, Guest..." plus the form
    } else {
    // Welcome back, username. Logout.
    } ?>

    ...And copying the login form from the wp-login.php file (which is in the root of a WP install). The code you'll need is around line 430.

    You'll have to remove some of the <p> tags, tweak the size of the form controls, and maybe change the classnames of the form controls so you can better style it.

    For the login form to work on every page, I think you'll need to modify the action attribute from action="wp-login.php" to action="\wp-login.php" (assuming WP is installed in the root of your domain's directory). -- The slash ("\") at the beginning of a URL is shorthand for the root directory.

    There's also wp_loginout() which provides a simple (text) login or logout link.

Topic Closed

This topic has been closed to new replies.

About this Topic