Use wp_login_url()
function with get_permalink()
as a parameter, if a user is not logged in. Something like this:
<a href="https://wordpress.stackexchange.com/questions/210374/<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
And wp_logout_url
function with get_permalink()
as a parameter, if a user is logged in.
<a href="https://wordpress.stackexchange.com/questions/210374/<?php echo wp_logout_url( get_permalink() ); ?>">Logout</a>
EDIT: instead of using 2 different functions, you may use
<?php wp_loginout(get_permalink()); ?>
that displays a login link, or if a user is logged in, displays a logout link
Related Posts:
- Show login greeting above sub-menu links?
- Menu not updating for logged in users after redirect
- Adding first / last CSS classes to menus
- How to change the wp-login.php page title?
- How build a custom login/register form with error handling?
- how to put the logo in the center of other items in the navigation bar
- renaming an admin menu item with decimal array index number
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Can we have a php “page” without a WordPress “page”?
- How to add active class to custom menu using while loop and wp_list_pages
- WordPress 4 invalid username special charachters issue
- wp_delete_auto_drafts() deletes links in menus
- Using a nonce in a Custom Login Form
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- Constructing a custom login form using ajax
- automated tests as a user?
- Logout and redirect using the WP Menu
- Creating new menu item
- Programmatically create menu with custom link
- Custom Loop through category menu to include sub categories
- PHP If user is logged in & on home page redirect
- wp nav menu: add attributes to menu items [duplicate]
- Admin username and password
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Change Navigation Bar based on logged in or not
- Is it necessary to sanitize wp_set_password user input?
- create a select input with menus created on a custom options page
- How to give new users two specific user role options upon WordPress user registration
- How to: PHP Log Out Link?
- Login/logout in header
- How can I Add a variable PHP in the Menu Nav
- Adding an Avatar to the Top Nav Bar
- Add data attribute to each li in menu
- Remove metabox from WordPress menu editor page?
- How to add an arrow to menu items has submenus
- wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
- getting logged in user info (wp-load.php) from parent directory
- Unique icons next to each WordPress menu item
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- Adding PHP in the menu
- New walker for walker_nav_menu to change inside container data
- Add data-id attribute to child page links
- Add login hyperlink to secondary navigation menu
- wp_nav_menu not working correctly in my underscores theme
- Lost in trying to create user database system
- Notice: Trying to get property of non-object
- How to use wp_nav_menu to create custom dropdown menu?
- PHP getting error when trying to access WP-Admin Dashboard
- Adding Additional Variables on Menus Page
- If user is logged in not working
- Nav-Menu not showing up
- How to tell if a user has gone in and created a menu
- Class for Selected Menu using wp_nav_menu
- Hard-coding a shortcode as the last menu item in primary navigation?
- Help with accessing wp-admin page and resolving error messages
- Nav Walker that shows only children and siblings of top level parent menu item
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- Featured image in menu wordpres
- PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
- Log out without confirmation request (nonce)
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Infinite loop when logging out using custom login form
- Issues adding Recaptcha v3 to WordPress Registration
- How to let mobile navigation menu close when link is clicked?
- Display specific page if user signed in
- Refresh page after login with litespeed cache
- PHP warning with code for nav menu walker [duplicate]
- Add element after navigation element title don’t works like I expect
- String replace for Login/Logout concatenation problem in menu
- 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)
- is_user_logged_in() not working in homepage
- How to create a sub-page of sub-page?
- Check if a user is logged into my WordPress site which is on a different server
- Widget Logic – display on page and all child
- Newbie question. Login/Registration. New PHP page
- How to list categories by page id in wordpress
- Adding button to wordpress menu
- wp_nav_menu doesn’t work in a duplicate server
- List users in a dropdown for login
- How I can add div to menu?
- wp_nav_menu prints children with parent name
- WP Admin Bar – Get current theme name as custom menu title
- White screen after login attempt
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- Submenu opened problem
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- How to replace wp-admin login page to another location?
- login redirect based on user role not work as expected
- How to add different menu items on different menus?
- Nav menù doesn’t display selected pages