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
-
Free up space on your Mac
You may not know it but there’s a lot of places on your shiny lovely Mac that can store lots of rubbish that you don’t actually need. We’ll explain a few places you can look to see if there’s a mass of files that you can safely delete and free up a few valuable gigs of space.
-
iPhone to Mac Wireless Networking
Connect to your jailbroken iPhone to your Mac to add or retrieve files and folders.
-
Is your site LIVE? FREE website monitoring sites
Keep a check on whether your website is live with these free and paid for tools.
-
Disable Flash in Chrome on Mac and PC
Sometimes you need to disable Flash. Maybe to test sites that run in both Flash and HTML and therefore automatically show you to the Flash elements or maybe you just don’t want Flash running in your browser. Whatever it is then here’s how to disable it in Chrome on a Mac.
-
Add category description if it exists
Find out how to add the category description to your category template in Wordpress.
-
iPhone Jailbreak for OS 3.0 Released
How to jailbreak your iPhone.
-
Backing up your Website using cPanel
Find out how to back up your website via cPanel
-
Domain Extensions. Are they important?
Does it make any difference what domain extension you choose? Find out more.
-
Web Browsing Tips #2: Tabbed Windows
Using tabbed windows in your web browser.
-
What's in a name? Choosing the right name for your company and website
Find out how to choose a great company name with a few basic tips.
-
Web Browsing Tips #3: Keyboard Shortcuts
Some web browsing keyboard shortcuts.
-
10 Top Widgets for your Mac
A list of useful widgets for your Mac, originally posted in 2009 so no longer useful for modern osX
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…