WordPress Login / Logout Link in Template
The standard Wordpress Login/Logout links often suffice but when you are building custom pages then the default Wordpress pages can look a little out of place on your site and therefore you may need to redirect your users to different pages and/or change the text links of those standard links.
The standard WordPress Login/Logout links often suffice but when you are building custom pages then the default WordPress pages can look a little out of place on your site and therefore you may need to redirect your users to different pages and/or change the text links of those standard links (boy, I’m saying standard a lot in this post!)
WordPress login/logout link
This link directs you to the standard WordPress Login page i.e. yoursite.com/wp-login.php and features the words “Log in” and “Log out” as the hyperlinks. This will send the user to the default login page and once logged in will redirect them to the WordPress Dashboard.
<?php wp_loginout();?>
WordPress Login/Logout page with custom links
This will send the user to the default login page and once logged in will redirect them back to the page they were previously on. This will send the user to the default login page and once logged in will redirect them to the WordPress Dashboard.
<?php if ( is_user_logged_in() ) { echo '<a href="'.wp_logout_url().'" title="Logout">Log out of my site</a>'; } else { echo '<a href="'.wp_login_url().'" title="Login">Log in to my site</a>'; } ?>
WordPress Login/Logout page with custom links and redirect to previous page.
This will send the user to the default login page and once logged in will redirect them back to the page they were previously on.
<?php if ( is_user_logged_in() ) { echo '<a href="'.wp_logout_url( get_permalink() ).'" title="Logout">Log out of my site</a>'; } else { echo '<a href="'.wp_login_url( get_permalink() ).'" title="Login">Log in to my site</a>'; } ?>
Custom WordPress Login/Logout pages with custom links
The following code will send the user to the page with ID of 22 to login (obviously you will need to add a login form to that page) and then will send them back to the home page when logged out.
<?php if ( is_user_logged_in() ) { echo '<a href="'.wp_logout_url( home_url() ).'" title="Logout">Logout</a>'; } else { echo '<a href="'.get_permalink( 22 ).'" title="Login">Login</a>'; } ?>
8 replies on “WordPress Login / Logout Link in Template”
Leave a Reply
-
HTML email signature in Apple Mail
Step by step guide on how to add an HTML signature to Apple Mail.
-
Secure your WordPress Blog
A guide to securing your WordPress website.
-
HTML email signature in Gmail
How to add a HTML signature in Gmail, without any text-decoration for links
-
Remove p tags from category description
By default Wordpress adds paragraph tags to category descriptions. Find out how to stop this.
-
DIV align bottom right (or left!)
Find out how to align a DIV to the bottom left or right.
-
Website Dimensions and Designing for the Web
What browser size should you design your website. Find out more.
-
Root Path and Configuration of your Website using php
Display the root path and configuration of your website by uploading a php file to your website.
-
HTML email signature in Zoho Mail
How to add a HTML signature in Zoho Mail. A very easy and stable solution.
-
FREE EU Cookie Law Script
If you haven’t already implemented the changes then we’ve put together a little bit of code to help you.
-
Remove the shadow from Mac Screen Grabs
How to remove the shadow from Apple Screengrabs.
-
10 Useful Sites for Web Developers
Some useful websites for web developers.
-
3 FREE Apps to protect your PC
A few free apps to help you protect your PC.
it’s working code. thanks a millions 🙂
Works very well
nice
Its not good code. After logged out its redirect to 1st post. when ur on homepage.
brilliant .
it’s working 🙂
I think i should use it in my new plugin .
Thanks
im thinking a alternative way to redirect a page !
Nice post thanks
Been looking how to do that for ages today ! Many thanks for the info…