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:
- 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. - 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.
0 Comments