Remove the Category Counts in the LearnDash Course List Category Dropdown

Written by Dan Mossop

In LearnDash, you might notice that each category in the Course List category dropdown shows a figure in brackets indicating the number of courses within that category. This automatic feature may not suit every site, so here's how to remove the category count and achieve a cleaner dropdown presentation.

Note, if you're using the LearnDash Course List module added to Divi by the Divi LearnDash Kit, the solution presented below will also work for you.

The image below illustrates the dropdown appearance before removing the course counts, and another showing how it looks afterward.

Before

After

Removing the LearnDash Category Course Count using PHP

You can use the following code snippet to remove the course counts from both the standard LearnDash category dropdown and the Divi LearnDash Course List module dropdown. This solution leverages a WordPress filter within LearnDash to alter the default output.

add_filter('ld_course_categorydropdown', 'remove_category_count_from_course_dropdown', 10, 3);

function remove_category_count_from_course_dropdown($ld_categorydropdown, $atts, $filter) {
    $ld_categorydropdown = preg_replace('/<option([^>]*?)>([^<]*?) \(\d+\)<\/option>/', '<option$1>$2</option>', $ld_categorydropdown);
    return $ld_categorydropdown;
}

Applying the Code

To implement this change, you have a couple of options:

  1. Child Theme: Add the above code snippet to the functions.php file of your child theme. This method is beneficial if you're comfortable modifying theme files and want to maintain changes when themes update.
  2. Plugin Approach: Alternatively, you can use a plugin like Code Snippets to add this functionality without directly editing theme files. This plugin provides a user-friendly interface for managing custom code snippets, making it a safer option for many site owners.

Conclusion

Adjusting the appearance of the category dropdown in your LearnDash course list or Divi LearnDash Course List module is a straightforward task that can enhance your site's aesthetics and usability. Whether you choose to make these tweaks through your child theme or a plugin, the change helps provide a cleaner interface for your learners. Tailoring your LearnDash setup to better meet your needs ensures a streamlined and user-friendly experience for everyone involved.

Seamlessly Integrate LearnDash with Divi!

Elevate your LearnDash LMS with the Divi LearnDash Kit from Divi Booster. This plugin adds custom LearnDash modules to Divi, resolves compatibility issues, and supports Divi design settings, creating a cohesive and visually appealing learning environment.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.