Login/logout link depends on user is logged
It’s common problem to create Login/Logout links in WordPress depended on user current state. We want to achieve this:
- Login/Register link – for not logged users
- Logout link – for logged users
Especially we want to have these links in WooCommerce where clients usually create accounts and log in or out. We want to have these links in the footer or inside of some widget. We can do this creating shortcode in WordPress. Open
functions.php file of your theme and paste there this code:
The last thing we should do is put our shortcode in the right place. For instance edit the footer and paste
[md_login_logout]. You don’t have to edit source file in your theme! We created shortcode and simply paste it in Gutenberg or other editor you use in WordPress.