< Toggle Sidebar > Toggle Sidebar

Breadcrumb Learndash Snippet

Adding proper breadcrumb trails to Learndash can be a bit tricky. This is because you have categories that are topics and lessons. It’s not that simple to understand without actually using Learndash.

In Learndash your top level item is a Course. Second Level is a Lesson. Third Level is a Topic.

This means if you are creating a breadcrumb, ideally you want it to show Course > Lesson > Topic.

The Code

This code gist will add in the breadcrumb path.

This is very useful in letting your customers know where to go. To use this code past it as is into your functions.php file in your Child Theme for your WordPress website.

This will work on any site using the Breadcrumbs feature from Yoast SEO.

Code Review

Lets review the code line by line.

The first line calls our function base on a hook provided by Yoast SEO. This hook calls out function found on line 3. We set the Global Post item to be present inside the scope of the function.

Next we check if we are in a lesson. If we are we get the details of the parent course and update the array that stored the breadcrumb path. This will update the breadcrumbs.

If we are not in a lesson, we then check if we are in a topic and perform a similar function, making sure we check our parent Lesson and Course, update the Array and add it to the Yoast SEO Breadcrumb object.

It took me a LONG time to work out exactly how to get this right but this has been reliable for over a year now. Hope you enjoy it and feel free to let me know if you need further instructions.

Breadcrumb Header for Divi Builder

Breadcrumb Module

Adds a new clean header with breadcrumbs powered by the Yoast SEO plugin. 
Learn More