LDX Design

Redirect Clicks on Course Content Table for Logged-Out Users

Affiliate Disclosure: We may be compensated if you use our links to make a purchase. We are extremely selective in who we partner with & only recommend products we believe in. Our affiliate relationships do not influence our recommendations.

By default, when a visitor—anyone not logged in to your site—lands on a LearnDash course page and tries to click a link in the course content table (it could be to a lesson, topic or quiz)… the page just reloads.

LearnDash has built-in course protection, so this is in place to stop a random visitor from accessing a course that they don’t have access to. The problem is that it redirects them back to the same page they are already on, essentially just reloading the course page.

This is less than ideal. But there’s a simple way to redirect these clicks on the course content table to any page of your choice:

  • a login page
  • a sales page powered by an ecommerce or membership plugin
  • your favorite cat video (probably not the best marketing strategy 😉)

This does involve a little PHP code, but don’t let it intimidate you. I’ll walk you through it.

Use the Code Snippets Plugin

The Code Snippets plugin is an alternative to adding code to your theme’s functions.php file. I believe it’s a much safer and more organized way to maintain code, especially for beginners and non-coders.

Recommended ProductKinsta 2 months of free hosting

We’ll be using this plugin to implement the code to redirect clicks on the course content table.

It’s a good idea to use this plugin for ALL future PHP code snippets that you would otherwise put in your functions.php file. And please don’t worry about plugin overload or “Ugh, I really don’t want to add another plugin to my site…” Code Snippets will not slow down your site.

Install & Activate the Plugin

  1. In your WordPress admin area, navigate to Plugins > Add New
  2. Search for “code snippets”
  3. Install & activate the plugin (author: Shea Bunge)

WordPress Code Snippets plugin card

Code for Course Content Table Redirects

Now that you’ve got the right tool in place, let’s add the code to actually implement our redirect.

  1. Navigate to Snippets > Add New
  2. Give your snippet a title. This is just internal naming, so choose anything you’d like.
  3. In the “Code” section, we’re going to add the following:
add_filter( "learndash_access_redirect", "ldfb_content_table_redirect", 10, 2 );

function ldfb_content_table_redirect() {

	$link = "https://learndash.com/";
	return $link;


Where it says https://learndash.com/, you would change that to the page on your site that you want to redirect people to. For example, it could be:

  • https://yoursite.com/login/ – if you’re using a custom login page
  • https://yoursite.com/product/name-of-product/ – if you’re using an ecommerce platform like WooCommerce
  • https://courses.yoursite.com/enroll-today/ – if you have one general sales page for all of your courses (perhaps you used a page builder to create a custom landing page, and are hosting your courses on a sub-domain)

The possibilities are endless. You can use any URL in the world! 🌏

(Optional) Description & Tags

It’s totally optional, but you can give your code snippet a description and/or some tags. These are just for internal organization, so use them as you’d like… or not at all.

Recommended Product

Rapyd WordPress Hosting
Rapyd just launched the fastest BuddyBoss, LearnDash & WordPress LMS hosting on the planet. Get 25% OFF with their early bird discount and lock-in up to 2 years of discounted pricing. From the creators of BuddyBoss.

Get 25% OFF Rapyd Today →

Run on Front-end Only

The final option is WHERE you’re going to allow this code to run. You can run it in the admin area, the front-end of your site, or both.

  • Choose Only run on site front-end

Code snippets run on front-end only checkbox

Because this code only applies to site visitors accessing your LearnDash course content table, there is no need to have it executed in the admin area. So just choose to run it on the front-end only.

Save & Activate

The final step is to click the “Save Changes and Activate” button at the bottom. Then navigate to a course page in a private browsing window (or logout of your current session) and click a link in the course content table. It should redirect you to the URL that you specified.


Customize the “Return to Course” Link in the LearnDash Navigation Widget


19 LearnDash Examples & Inspiration to Get Some Ideas Flowing


  1. Thank you very much! This is very useful.

  2. I am wondering if it is possible to trigger a pop up (containing login form) instead of redirect user to a different page ? I am using a pop up maker plugin.

    Also, do you do custom development Dave ?

    • It’s possible, but it depends on how the popup plugin works. Some popup plugins allow you to specify an ID inside of the href parameter. So instead of https://www.learndash.com/, you would use #name-of-id. And then you’d create a <div id="name-of-id"> somewhere on the page.

      And yes, I do custom development work, but am really slammed at the moment. I only have a small amount of time for little tweaks here and there.

  3. Monica

    Thank you. This is very useful!

  4. How can apply this to take a course button?

    • Hey Marcos — The easiest way to change where the “Take this Course” button links to is to set the course price type to “Closed.” This is in your course settings.

      Once you set it to Closed, you will get an additional field for “Button URL.” You can put any URL in that box, and people will be taken there when they click “Take this Course.”

  5. Thank you Dave. 🙂

  6. Khaly

    how to redirect user after completing a specific quiz to another quiz?

  7. Khaly

    how to redirect user after completing a specific quiz to another quiz?
    I mean override continue button to another different page

  8. Hi Dave,

    Thanks, this is very helpful, i was wondering though if there is a way to achieve this on a per course basis when using the custom grid as that displays all the available courses and instead of going into each course i am trying to redirect to a sales page.

    I am able to apply the change per each course inside when making it closed and changing the “take course” to redirect to a URL, but i want to achieve the same redirect from the custom course grid settings.

    Any ideas are appreciated.


    • Sorry Aly, but I don’t know how to do that. I’m not sure it’s possible, or if it is, it would require some custom code that I’m not aware of.

      My best recommendation would be to NOT use the course grid. If you create your own grid using a page builder or another plugin, you have more control over where the button/image for each grid item points to.

  9. Peter

    Thanks Dave. Excellent explanation. I have one question, how do we apply this to the logout link in the focus mode drop down menu? I can add my own logout menu item, but then there would be 2. Or how can I remove the default focus mode link altogether? Any ideas?

    One other thing, just uploaded the design upgrade Plugin and it’s fantastic. I noticed though that my course grid course button changed colours back to default after installing your plugin. Had had css you provided to change the colours. Maybe I’d need to re apply the css and refresh?


    • I don’t know how to remove the default logout link. There are no unique class or IDs applied, so you can’t really do it with CSS. And I haven’t seen any snippets that would allow you to do it programmatically.

      But I think the free Uncanny LearnDash Toolkit module “Login/Logout Redirects” should work. It will let you choose a URL to redirect all logouts to. You can learn more on their documentation site here.

      As for the button colors in your course grid, if you can send me a link to your grid page, I’ll look at the CSS and be able to send you some updated code. Also please remind me which color you want the buttons to use.

    • Peter

      Thanks, Dave. I actually got a reply from learndash themselves who have given the following resolution for the removal of the logout option on the FM menu. Leaving it here in case it helps anyone else:

      “You could use Custom CSS…the following Custom CSS will simply hide the last item in the menu (which is hardcoded to be the logout link)”

      .ld-user-menu-items a:last-child {
      display: none !important;

      It’s proving a little difficult to gain you access to our closed servers. Once I’ve worked this out I’ll reach out to you. Considering purchasing the pro version of DU plugin anyway. Will let you know!

    • Sounds good. Thanks Peter!

  10. Will

    Hey Dave, I been trying to redirect the LearnDash “Take this course” (logged in users) with Code Snippet but no luck. I’ve tried deactivating non important plugins.

    I’m using this code:

    add_filter(“learndash_course_join_redirect”, ‘learndash_course_join_redirect_fn’, 5, 2);
    function learndash_course_join_redirect_fn($link, $course_id) {
    $user_id = get_current_user_id();
    // You can set the link below
    $link = “http url redirect here”;
    return $link;

    No errors on the page. It simply keeps redirecting me to PayPal for checkout instead of a custom Gravity Forms with Stripe.

  11. Parabéns pelo belíssimo Post muito bem explicado. Eu Sou desenvolvedor web em WordPress e já uso o Learndash, em meu projetos. Porém sempre achei que para um excelente plugin, deveria ter uma redirecionamento mais compatível. Vosso site já esta nos meus favoritos e desejo muito aprender.

  12. Hi Dave

    How can I set the logout redirect to be the home page of my website instead of an empty profile page?



    • Hi Paul — There are several ways to do this, but one of the easiest, and the one I’d recommend, is using the Uncanny Toolkit for LearnDash. Turn on the module for Login/Logout Redirects and set the logout redirect to whatever page you want.

  13. Paul Burton

    Hi Dave

    Thanks for the recommendation it has sorted my problem



  14. Angel

    How can apply this to”Login to Enroll” button?

  15. Hi Dave, I hope you’re well.

    I’m using buddyboss theme with Learndash. I want to redirect user on custom profile page when user click on course instructor name. Please tell me about solution.


    • LearnDash doesn’t display the course instructor name anywhere, so I’m guessing it’s BuddyBoss that is doing that.

      I don’t think there’s a hook for that, which means you’ll probably need to customize the template file. You can ask BuddyBoss support to confirm.

Leave a Reply

Your email address will not be published. Required fields are marked *