Snippet: Add CSS Classes to LearnDash Course Rows Based on Progress
Style not-started, in-progress and completed courses differently in the ld_course_list output. How the row template builds its class, the filter and actions it offers, and a snippet that adds status classes and a badge.

A list of courses is more useful when the learner can see at a glance which ones they have finished, which are under way and which they have not opened. The core [ld_course_list] shortcode prints every course row with the same markup, but the ld30 row template passes its class attribute through a filter and fires actions around the title. LearnDash 4.18.0.1 gives you enough there to add a progress class and a badge with no template override. This snippet does both and explains the one trap in the filter's signature.
The row template
themes/ld30/templates/course/partials/row.php is rendered once per course by the course list template with course_id and user_id. It starts by computing $course_class = apply_filters( 'learndash-course-list-shortcode-course-class', '' ), fires learndash-course-row-before with the course ID and user ID, then opens a div whose id is course-{user}-{course} and whose class is the filtered value. Inside it fires learndash-course-row-status-before and learndash-course-row-link-before, prints the title link, and fires learndash-course-row-certificate-before, -expand-before and -expand-after.
The trap: the class filter receives only the empty string, with no course or user argument. It does run inside the list loop, though, where the global post is the current course, so get_the_ID() returns the course ID and get_current_user_id() the viewer.
Snippet: status classes on the row
<?php
add_filter(
'learndash-course-list-shortcode-course-class',
function ( $class ) {
$course_id = get_the_ID();
$user_id = get_current_user_id();
if ( ! $course_id || 'sfwd-courses' !== get_post_type( $course_id ) ) {
return $class;
}
$classes = array( 'wwc-course-row' );
if ( $user_id && sfwd_lms_has_access( $course_id, $user_id ) ) {
// Returns not_started, in_progress or completed.
$status = learndash_course_status( $course_id, $user_id, true );
$classes[] = 'wwc-course-' . str_replace( '_', '-', $status );
$classes[] = 'wwc-course-enrolled';
} else {
$classes[] = 'wwc-course-not-enrolled';
}
return trim( $class . ' ' . implode( ' ', $classes ) );
}
);
The access check separates enrolled learners, who have a status, from visitors and non-enrolled users, who get a single class. learndash_course_status() with the third argument true returns the slug rather than the translated label, which is what you want in a class name.
Snippet: a badge before the title
Classes let you colour the row; a badge says the status in words. Hook the action that fires before the title link:
<?php
add_action(
'learndash-course-row-status-before',
function ( $course_id, $user_id ) {
if ( empty( $user_id ) || ! sfwd_lms_has_access( $course_id, $user_id ) ) {
return;
}
$slug = learndash_course_status( $course_id, $user_id, true );
$label = learndash_course_status( $course_id, $user_id );
printf(
'<span class="wwc-course-badge wwc-course-badge-%1$s">%2$s</span> ',
esc_attr( str_replace( '_', '-', $slug ) ),
esc_html( $label )
);
},
10,
2
);
Calling the function twice is cheap because the second call reads cached progress, and it gives you the translated label, Not Started, In Progress or Completed, without maintaining your own strings.
CSS
.wwc-course-row { padding-left: 0.75rem; border-left: 4px solid #d0d0d0; }
.wwc-course-in-progress { border-left-color: #f0a500; }
.wwc-course-completed { border-left-color: #2e8b57; }
.wwc-course-completed a { text-decoration: line-through; }
.wwc-course-badge {
display: inline-block;
padding: 0.1rem 0.5rem;
border-radius: 999px;
font-size: 0.75rem;
background: #eee;
}
.wwc-course-badge-in-progress { background: #fff1cc; }
.wwc-course-badge-completed { background: #d9f2e3; }
The row's own id attribute is also available if you need to target a single course and learner in CSS or JavaScript.
When this template is not used
Three situations bypass row.php:
- Course Grid is active. The core shortcode's
course_gridattribute defaults to true, and with the add-on installed the list renders through Course Grid's legacy card instead. Passcourse_grid="false"to get the row template back, or style Course Grid's own enrolled and completed ribbons, which our catalog options comparison describes. - The theme overrides the partial. Check for
learndash/ld30/course/partials/row.phpin the theme; the template system guide explains the lookup order. - Legacy templates. Sites still on the legacy template set do not load ld30 partials at all.
Using the classes for filtering
Once rows carry status classes, a small script can offer "show in progress only" buttons without a new query. Add three buttons above the list, give each a data-status attribute, and on click toggle a wwc-hide class on rows whose status class does not match. The rows keep their markup, LearnDash's own expand behaviour keeps working, and the page stays a single request. Because the classes are generated server-side for the logged-in learner, the filter reflects real progress rather than a cached state. Keep the script in your child theme and enqueue it only on pages that contain the list, for example by checking has_shortcode() on the post content.
Not-enrolled rows
Rows for courses the learner has not joined get only the wwc-course-not-enrolled class. That is deliberate: the row template does not print a price, and a status badge on a course someone has not started reads as noise. If you want a call to action on those rows, hook learndash-course-row-expand-after and print a short link to the course page, using learndash_get_course_price( $course_id ) to decide between "Enrol for free" and "View course" wording. Keep it as a link rather than the payment button, since the payment button is designed for the course page and its enrolment forms.
Profile and group lists
The [ld_profile] course list and the group course list use different partials with their own hooks, so these snippets affect only [ld_course_list] and the Course List block. The profile rows already carry status classes of their own, which is why they are not covered here.
Testing
- Place
[ld_course_list course_grid="false"]on a test page. - View as a visitor: rows have
wwc-course-not-enrolledand no badge. - Enrol a learner, view as them: not-started classes and badge; complete a lesson, then the course, and watch both change.
- Inspect a row's class attribute to confirm nothing else on the page is affected.
When to get help
Styling by status is an hour's work. A full "my learning" dashboard with filters, sorting by progress and resume links is a small build, and our LearnDash services team does those with UI and UX design included; a LearnDash developer can also port these classes into a Course Grid custom card.
Frequently asked questions
Why does the course class filter not receive the course ID?
The filter is called with only the empty string. Because it runs inside the list loop, get_the_ID() returns the current course and get_current_user_id() the viewer.
Which function gives the progress status slug?
learndash_course_status( $course_id, $user_id, true ) returns not_started, in_progress or completed; without the third argument it returns the translated label.
My classes do not appear with Course Grid installed. Why?
Course Grid replaces the core list template unless the shortcode has course_grid="false". Add the attribute or style Course Grid's ribbons instead.
Can I add a badge instead of a class?
Yes. Hook learndash-course-row-status-before, which fires inside the row before the title link with the course ID and user ID.
Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.
