LDX Design

LearnDash Design & Tutorials

LearnDash Design & Tutorials

Redirect Clicks on Course Content Table for Logged-Out Users

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 by Shea Bunge 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.

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

NOTE
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.

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.

Previous

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

Next

17 LearnDash Examples & Inspiration to Get Some Ideas Flowing

9 Comments

  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. 🙂

Leave a Reply

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

Powered by WordPress & Theme by Anders Norén