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?


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().

/* Template Name: (#56656) LoginLogoutEtc. */

dynamic_sidebar( 'sidebar_name' );

// Links to login/logout

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

// In case the user wants to log out again
if ( is_user_logged_in() )
         '<a href="%s" title="Logout">Logout</a>'

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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