LMS & eLearning

Building a Custom LearnDash Course Navigation Menu With Sections

Build your own LearnDash course outline menu with section headings, lessons, topics, completion ticks and locked states, from learndash_get_course_lessons_list(), learndash_30_get_course_sections() and the step helpers.

Building a Custom LearnDash Course Navigation Menu With Sections

LearnDash ships a Course Navigation widget, the [ld_navigation] shortcode and the Focus Mode sidebar, all rendering the same ld30 navigation markup. When a design calls for a different outline, such as a numbered syllabus, collapsible sections or an outline inside a page builder column, rebuilding that markup with CSS gets painful. Generating your own menu from LearnDash's data is often simpler. This tutorial builds one for LearnDash 4.18.0.1 with section headings, lessons, nested topics, completion ticks, locked states and the current step highlighted, using the same functions the built-in navigation uses.

The data functions

  • learndash_get_course_lessons_list( $course_id, $user_id, $query_args ) returns the course's lessons in course order. Each item is an array with sno, post (the lesson WP_Post), permalink built with the course context, sample (is_sample or is_not_sample), lesson_access_from for drip-fed lessons, and status, which is completed, notcompleted or notavailable when a drip date has not arrived. It respects the course's lesson pagination unless you pass 'pagination' => false.
  • learndash_30_get_course_sections( $course_id ) returns the course's section headings as an array keyed by the ID of the first lesson in each section; each value has a post_title and a steps list. It is built on learndash_course_get_sections() and is what the ld30 lesson list uses to print section headings.
  • learndash_get_topic_list( $lesson_id, $course_id ) returns the topic posts of a lesson in order.
  • learndash_is_topic_complete( $user_id, $topic_id, $course_id ) and learndash_get_step_permalink( $step_id, $course_id ) complete the picture for topics.

The built-in widget, LearnDash_Course_Navigation_Widget, wraps learndash_30_get_course_navigation(), which in turn calls the lessons list function, so your menu and LearnDash's own will always agree on order and status.

The shortcode

<?php
/**
 * Escaped anchor used by the course outline.
 *
 * @param string $url   Link target.
 * @param string $text  Link text.
 * @param array  $attrs Extra attributes.
 * @return string
 */
function wwc_outline_anchor( $url, $text, $attrs = array() ) {
    $attrs     = array_merge( array( 'href' => esc_url( $url ) ), $attrs );
    $attr_html = '';
    foreach ( $attrs as $attr_name => $attr_value ) {
        $attr_html .= sprintf( ' %1$s="%2$s"', esc_attr( $attr_name ), esc_attr( $attr_value ) );
    }
    return '<a' . $attr_html . '>' . esc_html( $text ) . '</a>';
}

/**
 * [wwc_course_outline course_id=""] - section, lesson and topic outline for the current course.
 */
function wwc_course_outline_shortcode( $atts ) {
    $atts      = shortcode_atts( array( 'course_id' => 0 ), $atts );
    $course_id = absint( $atts['course_id'] ) ? absint( $atts['course_id'] ) : learndash_get_course_id();

    if ( ! $course_id ) {
        return '';
    }

    $user_id    = get_current_user_id();
    $current_id = get_the_ID();
    $lessons    = learndash_get_course_lessons_list( $course_id, $user_id, array( 'pagination' => false ) );
    $sections   = learndash_30_get_course_sections( $course_id );

    if ( empty( $lessons ) ) {
        return '';
    }

    $html = '<nav class="wwc-outline" aria-label="' . esc_attr__( 'Course outline', 'wwc' ) . '"><ol class="wwc-outline__lessons">';

    foreach ( $lessons as $item ) {
        $lesson    = $item['post'];
        $lesson_id = $lesson->ID;

        if ( isset( $sections[ $lesson_id ] ) ) {
            $html .= '<li class="wwc-outline__section" role="presentation">' . esc_html( $sections[ $lesson_id ]->post_title ) . '</li>';
        }

        $topics     = learndash_get_topic_list( $lesson_id, $course_id );
        $is_current = ( $lesson_id === $current_id );
        $has_child  = false;

        foreach ( (array) $topics as $topic ) {
            if ( $topic->ID === $current_id ) {
                $has_child = true;
            }
        }

        $classes = array( 'wwc-outline__lesson', 'is-' . sanitize_html_class( $item['status'] ) );
        if ( $is_current || $has_child ) {
            $classes[] = 'is-current';
        }

        $html .= '<li class="' . esc_attr( implode( ' ', $classes ) ) . '">';

        if ( 'notavailable' === $item['status'] ) {
            $html .= '<span class="wwc-outline__link">' . esc_html( get_the_title( $lesson ) ) . '</span>';
        } else {
            $link_attrs = array( 'class' => 'wwc-outline__link' );
            if ( $is_current ) {
                $link_attrs['aria-current'] = 'page';
            }
            $html .= wwc_outline_anchor( $item['permalink'], get_the_title( $lesson ), $link_attrs );
        }

        if ( ! empty( $topics ) ) {
            $html .= '<ul class="wwc-outline__topics">';
            foreach ( $topics as $topic ) {
                $done   = $user_id && learndash_is_topic_complete( $user_id, $topic->ID, $course_id );
                $topic_attrs = ( $topic->ID === $current_id ) ? array( 'aria-current' => 'page' ) : array();
                $html       .= sprintf(
                    '<li class="wwc-outline__topic%1$s%2$s">%3$s</li>',
                    $done ? ' is-completed' : '',
                    $topic->ID === $current_id ? ' is-current' : '',
                    wwc_outline_anchor( learndash_get_step_permalink( $topic->ID, $course_id ), get_the_title( $topic ), $topic_attrs )
                );
            }
            $html .= '</ul>';
        }

        $html .= '</li>';
    }

    return $html . '</ol></nav>';
}
add_shortcode( 'wwc_course_outline', 'wwc_course_outline_shortcode' );

Placed in a sidebar on lesson and topic pages, it detects the course with learndash_get_course_id(), which resolves the course from the current step, including when shared steps are enabled and the course comes from the URL. On other pages pass course_id explicitly.

Why the menu does not decide access

The menu links to every available lesson and only removes the link for drip-locked lessons, which LearnDash marks notavailable. It does not try to enforce linear progression or enrollment. LearnDash already enforces both when the step loads, redirecting or showing a progression message, so duplicating that logic in a menu only creates a second place for bugs. If you want visual locks for linear courses, add a class when learndash_lesson_progression_enabled( $course_id ) is true and the previous lesson's status is not completed, but leave the link in place.

Styling the outline

.wwc-outline__lessons { list-style: none; margin: 0; padding: 0; counter-reset: lesson; }
.wwc-outline__section { margin: 1.25rem 0 0.5rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #6b7280; }
.wwc-outline__lesson { counter-increment: lesson; padding: 0.5rem 0; border-bottom: 1px solid #f1f5f9; }
.wwc-outline__lesson > .wwc-outline__link::before { content: counter( lesson ) ". "; color: #9ca3af; }
.wwc-outline__lesson.is-completed > .wwc-outline__link::after { content: " \2713"; color: #16a34a; }
.wwc-outline__lesson.is-notavailable { opacity: 0.55; }
.wwc-outline .is-current > a { font-weight: 700; color: #1d4ed8; }
.wwc-outline__topics { list-style: none; margin: 0.35rem 0 0 1.25rem; padding: 0; font-size: 0.9375rem; }
.wwc-outline__topic.is-completed a::after { content: " \2713"; color: #16a34a; }
.wwc-outline__lesson:not(.is-current) .wwc-outline__topics { display: none; }

The last rule shows topics only for the current lesson, which keeps long courses readable. Remove it for a fully expanded syllabus. Lesson status classes come straight from LearnDash's own status values, so is-completed, is-notcompleted and is-notavailable are the three you will see.

Quizzes in the outline

Lesson-level and topic-level quizzes are not in the lessons list. Add them with learndash_get_lesson_quiz_list( $lesson, $user_id, $course_id ) after each lesson's topics; each entry carries the quiz post, a permalink and a status. Course-level final quizzes can be appended after the loop from learndash_get_course_quiz_list( $course_id, $user_id ). Show them with a distinct icon, since learners scan the outline for assessments.

Performance

For a course with twenty lessons and a hundred topics the shortcode runs one lessons query, a sections lookup and one topic list per lesson, each served from LearnDash's course steps cache, plus one completion check per topic from user meta that is already loaded. That is light. If you show the outline on every page of a large site, cache the rendered HTML per user and course in a short transient and clear it from the completion hooks.

Collapsible sections

For long courses, make each section heading a button that collapses the lessons beneath it. Wrap each section's lessons in their own list in the loop, give the heading an aria-expanded attribute and an aria-controls pointing at the list, and toggle both with a few lines of JavaScript. Start the section containing the current step expanded and the others collapsed. Because the section map from learndash_30_get_course_sections() is keyed by the first lesson of each section, you know exactly where each group starts while looping through the lessons.

Placing the outline in a sidebar

Most themes give lessons and topics a widget area or a block template part. Drop the shortcode there and the outline follows the learner from step to step, because it reads the course from the current post each time it renders. On pages outside a course it prints nothing, so the same sidebar can stay on the rest of the site without an empty box.

Testing

Build a course with two sections, a drip-fed lesson, a sample lesson and topics. Check the outline as a visitor, as a learner part-way through, and with shared steps enabled. Confirm the section headings appear above the right lessons, the drip-fed lesson is unlinked until its date, the current lesson expands with its topics, and the ticks match the learner's profile. Compare against the built-in navigation widget on the same page to spot ordering differences.

When to get help

The outline takes an afternoon. Outlines with progress rings per section, estimated durations or search are bigger builds; our LearnDash services team builds them, and a LearnDash developer can turn the outline into a block or a Focus Mode sidebar replacement. The Focus Mode filters reference covers the sidebar side.

Frequently asked questions

How do I get LearnDash lessons in course order?

Use learndash_get_course_lessons_list(). It returns lessons in the course builder order with permalink and status for the user. Pass 'pagination' => false to get all of them.

How do I get the section headings?

learndash_30_get_course_sections( $course_id ) returns them keyed by the first lesson ID of each section, so you can print a heading before that lesson.

What does the notavailable status mean?

The lesson is drip-fed and its availability date has not arrived for this learner.

Should the menu block access to locked lessons?

No. LearnDash enforces enrollment and progression when the step loads. Use classes for visual locks and leave access control to LearnDash.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Free consultation

Need help with LearnDash?

Tell us what you are working on. A developer who does this every week reads your message and replies within one business day with next steps and a free quote.

  • Free consultation and quote
  • NDA on request
  • You own the source code
  • Reply within one business day

Tell us about your project

Add budget and timeline optional, helps us quote faster

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.