Recently, one of our members asked if there was a way to display the LearnDash login form only to users who are logged out. They are using an Elementor template with pricing tables, and wanted to provide a way for logged out users to quickly login instead of accidentally trying to buy a course they had already purchased.
They are using the default LearnDash login form, and wanted to display a link/button in their Elementor template. We’ll explain how to include a button anywhere on your site to only logged out users. You can use this with Elementor, another page builder, or anywhere else on your site (using the block editor or classic editor). Anywhere that accepts WordPress shortcodes will work.
To achieve this, we’re going to use the free Uncanny Toolkit for LearnDash plugin. Within this plugin, you can enable a module called Show or Hide Content. This module provides a few shortcodes you can use to check whether a user is logged in or logged out, and then display content to one or the other.
Enable the “Show or Hide Content” Module
Each module in the Uncanny Toolkit needs to be enabled manually. After installing & activating the plugin…
- Navigate to Uncanny Toolkit > Modules
- Use the search bar to search for “show or hide content.” Simply typing “show” should be enough.
- Click the toggle in the top corner to enable the module. It will look like this:
Insert the Shortcodes
Now that the shortcodes are ready to use, navigate to the place where you want to insert your LearnDash login form.
Use the following shortcodes:
[/uo_show] shortcodes are what check if a user is logged out. If they are, it will display what is inside of those two shortcodes. If not, the contents do not get displayed.
shortcode is what displays a button that opens the LearnDash login modal.
You can customize the button text by adding a parameter to the
shortcode, like this:
Change the text inside the quotes to whatever you’d like.
It’s worth noting that you can show content only to logged in users with the same Uncanny Toolkit shortcode. Simply change “loggedout” to “loggedin,” like this:
[uo_show for='loggedin']Whatever content you want to display[/uo_show]