Disclaimer

This blog is kind of my own personal work Notebook, and the processes below are only guaranteed to work for my specific configurations. So, use this info at your own risk, and please understand I won't be able to provide any help if you break something

Thursday, August 12, 2021

Adding LogIn / LogOut links to WordPress menus

The Problem: 

Adding LogIn / LogOut links to WordPress menus depending on whether the user is logged in or out


The Solution: 

1- Install the 'Login Logout Menu': https://wordpress.org/plugins/login-logout-menu/


2- Add to functions.php

/**

* Filter to redirect a user to a specific page after login.

*

* @return [URL] login url with page slug on which it will be redirected after login

*/

add_filter( 'login_logout_menu_login', 'loginpress_login_menu_login_redirect' );

function loginpress_login_menu_login_redirect()

{

return wp_login_url( '/members' );

}

/**

 * Filter to redirect a user to a specific page after logout.

 *

 * @return [URL] logout url with page slug on which it will be redirected after logout

*/

add_filter( 'login_logout_menu_logout', 'loginpress_login_menu_logout_redirect' );

function loginpress_login_menu_logout_redirect()

{

return wp_logout_url( '/' );

}

No comments:

Post a Comment