Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to create a template file and put there a login code, register code and widget code. I can do it for a widget, but I do not know how to do such thing for login and register. Any advice how to accomplish that?

share|improve this question

2 Answers 2

up vote 2 down vote accepted
+100

There's wp_register() which displays either a link to the registration or a login link.

Then you got wp_loginout() that has either a login or logout link - depending on the login status of the user.

Another thing you could do is just adding a wp_login_form().

You can also use the plain wp_login_url( $redirect ) to construct a link yourself, where $redirect would be the query args that you want to append. Then there's also wp_logout_url() to do the opposite.

To check if a user is logged in, just use is_user_logged_in().

<?php
/* Template Name: (#56656) LoginLogoutEtc. */

dynamic_sidebar( 'sidebar_name' );

// Links to login/logout
wp_loginout();

// User is not logged in
if ( ! is_user_logged_in() )
{
    // Offer the login form
    wp_login_form();
}
// Multisite: User may want to register
elseif ( is_multisite() AND ! is_user_member_of_blog() )
{
    wp_register();
}

// In case the user wants to log out again
if ( is_user_logged_in() )
{
    printf(
         '<a href="%s" title="Logout">Logout</a>'
        ,wp_logout_url();
    );
}
share|improve this answer

You can use login and register forms as widgets also. Register more widget areas and use some plugins there. Just search for "wordpress login widget" and "wordpress registration widget".

Registration Widget
Sidebar Login

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.