Using wp_logout_url()
is your best choice.
You will need to create a <a>
tag and in the href attribute output wp_logout_url()
<a href="<?= wp_logout_url("https://wordpress.stackexchange.com/"); ?>" title="Logout">Logout</a>
I passed /
as an argument because after the user will click the link he will be redirected back to the homepage, you can change it to what ever you want
EDIT
Using code snippets you could create a shortcode and then use it, almost, where ever you want.
add_shortcode('bt_custom_logout_link', 'bt_custom_logout_link');
function bt_custom_logout_link ($atts) {
$link = '<a href="' . wp_logout_url("https://wordpress.stackexchange.com/") . '" title="Logout">Logout</a>';
return $link;
}
This function will register a new shortcode named bt_custom_logout_link
, to use it you need to type it like this [bt_custom_logout_link]
Related Posts:
- How to: PHP Log Out Link?
- Login/logout in header
- Check if user had autologin & if so, logout
- Change button link to add nonce
- Change Login or Logout text based on status
- User registration followed by automatic login
- Can I use the same nonce for multiple requests on the same page?
- How to use nonce with front end submission form?
- Adding “Remember Me” in custom login
- How to change the wp-login.php page title?
- How build a custom login/register form with error handling?
- Do I require the use of nonce?
- How to log out everywhere else, destroy all sessions “all other devices”?
- Security – Ajax and Nonce use [closed]
- WordPress 4 invalid username special charachters issue
- How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
- How to resolve error “Cookies are blocked due to unexpected output.”?
- Using a nonce in a Custom Login Form
- Constructing a custom login form using ajax
- automated tests as a user?
- Remove username in emails or swap username for email
- woocommerce and is_user_logged_in() if not redirect to homepage
- When must I use and verify nonce?
- Check if user is logged in when clicking certain links on certain pages
- What SQL / WordPress queries would need a nonce?
- PHP If user is logged in & on home page redirect
- WordPress shows registration link for non logged users
- Creating login session via CURL
- Admin username and password
- Recovering WP Login Credintials in Code?
- WP nonce invalid
- Is it necessary to sanitize wp_set_password user input?
- WordPress custom login form using Ajax
- How to give new users two specific user role options upon WordPress user registration
- Wp-login appears White Screen, Error: Cannot modify header information
- Why is my cookie not unsetting upon logout? [closed]
- User management system similar to wordpress one?
- Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
- How to debug my custom login form looping intermittently
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Problem with login form
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Form Security: nonce vs. jQuery
- Log in / Log Out Custom Button
- Should `wp_login` be used since it’s deprecated?
- How to redirect users based on role and content of redirect_to?
- Change CSS based on is_user_logged_in
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- How can I open up my administrative panel to everyone?
- Force Users To Relogin
- How to hook a logout funtion for specific usr role in wordpress?
- How can I add a new row in a separate database when someone registers via WordPress?
- One account with multiple logins
- Lost in trying to create user database system
- Logout redirects to default page
- Shortcode to log user into current URL
- PHP getting error when trying to access WP-Admin Dashboard
- I installed WordPress locally now how do I login?
- If user is logged in not working
- Change homepage content if user is logged in – BuddyPress
- Show login greeting above sub-menu links?
- is_user_logged_in returning nothing on custom page
- Help with accessing wp-admin page and resolving error messages
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- Can’t log in to WordPress wp-admin after adding code to functions.php
- Reliable way to add nonce to HTTP Header in WordPress?
- Admin Panel 404 Error after login
- PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
- How to block specific user id in custom login form?
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- Restrict wordpress access to logged users only
- Infinite loop when logging out using custom login form
- how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
- Issues adding Recaptcha v3 to WordPress Registration
- Display specific page if user signed in
- Refresh page after login with litespeed cache
- Redirect after login depending on the URL
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- How do I send a POST request with params with WordPress REST API
- wp-login.php?redirect_to=https problem
- is_user_logged_in() not working in homepage
- Check if a user is logged into my WordPress site which is on a different server
- Newbie question. Login/Registration. New PHP page
- Adding a sidebar to wp-login.php
- List users in a dropdown for login
- Nonce fail after second submit attempt
- Not logged in when using http
- add bootstrap modal after login in wordpress
- White screen after login attempt
- Using Nonce for my Form
- Redirect users not logged in to the standard login page (and back) from some posts and pages
- How to replace wp-admin login page to another location?
- login redirect based on user role not work as expected
- How to change wp-admin and wp-login urls
- How do I do so that people can register on my wordpress site?
- wp_login_url always redirects me to wp-admin
- I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”
- change div text and link for logged in users