WordPress.org

Support

Support » How-To and Troubleshooting » Simple Login Box in Header

Simple Login Box in Header

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Have you try this link http://www.wprecipes.com/add-a-login-form-on-your-wordpress-theme ?

    I’ve tried it and have it modified like this:

    <?php
    
    function form_login( $args = array() ) {
    	$defaults = array( 'echo' => true,
    						'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
    	 					'form_id' => 'loginform',
    						'label_username' => __( 'Username' ),
    						'label_password' => __( 'Password' ),
    						'label_remember' => __( 'Remember Me' ),
    						'label_log_in' => __( 'Login' ),
    						'id_username' => 'user_login',
    						'id_password' => 'user_pass',
    						'id_remember' => 'rememberme',
    						'id_submit' => 'wp-submit',
    						'remember' => true,
    						'value_username' => '',
    						'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
    					);
    	$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
    
    	$form = '
    		<form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
    			' . apply_filters( 'login_form_top', '', $args ) . '
    			<label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
    				<span><input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="15" tabindex="10" /></span><br>
    			<label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
    				<span><input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="15" tabindex="20" /></span><br>
    			' . apply_filters( 'login_form_middle', '', $args ) . '
    			' . ( $args['remember'] ? '<label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever" tabindex="90"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label>' : '' ) . '
    				<input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" tabindex="100" />
    				<input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
    
    			' . apply_filters( 'login_form_bottom', '', $args ) . '
    		</form>';
    
    	if ( $args['echo'] )
    		echo $form;
    	else
    		return $form;
    }
    
    ?>

    Have it a go, and let us know what the result you get, just to remind you. You might have to play around with css to get the result you want.

    Oh and also, i haven’t figure out too about the function wp_register() it just doesn’t show up anything. Maybe guys from wordpress will make it clearer.

    cheers,

    oh and yes, i forgot to mention that i also combine it with function wp_login_form() to make that code, a little mix here and there

    esmi

    @esmi

    Forum Moderator

    If you download the Emporium theme, it contains a custom login widget (using wp_login_form()). Perhaps you can grab some code from there?

    Okay,

    I figure it now, it was my bad i didn’t notice 1 tiny option. So the step is like this:
    1. Make sure you enable the “Anyone can register” option in general setting, if you are not sure read this article http://www.dummies.com/how-to/content/how-to-allow-user-registration-on-your-wordpress-n.html

    2. If you are making your own theme write this on your header.php on your theme folder around line 77 (after the </hgroup> or put it somewhere else you like just don’t broke the other stuffs)

    <!--Login Form Begin-->
      <?php if (!is_user_logged_in()){ ?>
      <div id="login-form"><!--create new id on css just to make it easy to order things-->
      <?php form_login() ; ?><!--this is my own modification code because i hate the paragraph used on wp_login_form(), i wrote it on function.php in my theme folder-->
       <?php wp_register('', ''); ?>&nbsp;|&nbsp;<a href="<?php echo wp_lostpassword_url( get_permalink() ); ?>" title="Lost Password">Lost Password</a>
      </div>
      <?php } else { ?>
      <div id="login-form">
      <p>&nbsp;</p>
      <p>&nbsp;</p>
       <p>&nbsp;</p>
      <?php wp_register('<p>', '</P>'); ?>
      <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>
      </div>
      <?php }?>
      <!--Login Form End-->

    3. modified your style.css to get the look you want
    4. If you do anything right you’ll get something similar to https://dl.dropbox.com/u/91247708/ss%20frmlogin.jpg

    Hope you’ll find it usefull

    Cheers,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Simple Login Box in Header’ is closed to new replies.
Skip to toolbar