E-Learning WordPress Tips & Tricks

LearnDash ProTips: Adding A Custom Course Level

LearnDash gives you courses, lessons, and topics, but sometimes you need another level. Here is a ProTip on adding a custom course level, so your content structure can match how your learning actually flows.

Suraj M Suraj M 6 min read
LearnDash ProTips: Adding A Custom Course Level
Do note, the below solution is not compatible with LearnDash 3.0+

LearnDash competes as one of the most powerful LMS plugins for WordPress out there, with a fairly large and an active user base. This is, in part, because of flexibility that it offers to all the three entities associated with any LMS software: the plugin developers, the course content creators and the end users i.e. the learners. The code for the plugin is structured such that it’s but a piece of cake for developers like myself to add in tons of cool features and functionality, as per usage and requirements.

As for course designers, LearnDash let’s you conveniently break down the content flow into three distinct levels: Courses, Lessons and Topics, with the hierarchy falling in that same order. So if Mathematics is your Course, Algebra could be one possible Lesson, with Polynomials as one of the Topics within the lesson.

Adding A Custom Course Level In LearnDash

Consider this: say I have an elearning platform that caters to large demographic; from students still in school to graduates looking to add to their skill set via an advanced online course, how does ‘Mathematics’ fit in there? Or what if you’re looking to further divide Topics in sub topics of some sort? Wouldn’t it be nice to add in your own levels of content for LearnDash?

If you’ve put the two and two together by now, LearnDash does let you play around with the hierarchy of levels for course content and tweak it to your liking. With a bit of custom coding, one can easily write a plugin that adds in this particular functionality to LearnDash. Here’s how:

Step 1. Add A Custom Post Type: Let’s Call It A ‘Section’

LearnDash maintains hierarchy levels as custom post types. This post type will be use to create a new level of hierarchy, called Sections. Sections would be used to group similar Courses together. For eg. a Section called “Higher Secondary” will contain Courses that are Mathematics, Science, English, and Commerce.

Create a plugin with any desired name and the following code to the main php file. (plugin_name.php)

//Add custom post type section.

add_action('admin_menu', 'wdm_add_section_post_type');

function wdm_add_section_post_type()

{

   $labels = array(

       'name'               => _x('Sections', 'post type general name', 'your-plugin-textdomain'),
       'singular_name'      => _x('Section', 'post type singular name', 'your-plugin-textdomain'),

       'menu_name'          => _x('Sections', 'admin menu', 'your-plugin-textdomain'),

       'name_admin_bar'     => _x('Section', 'add new on admin bar', 'your-plugin-textdomain'),

       'add_new'            => _x('Add New', section, 'your-plugin-textdomain'),

       'add_new_item'       => __('Add New Section', 'your-plugin-textdomain’),

       'new_item'           => __('New Section', 'your-plugin-textdomain'),

       'edit_item'          => __('Edit Section', 'your-plugin-textdomain'),

       'view_item'          => __('View Section', 'your-plugin-textdomain'),

       'all_items'          => __('All Sections', 'your-plugin-textdomain'),

       'search_items'       => __('Search Sections', 'your-plugin-textdomain'),

       'parent_item_colon'  => __('Parent Sections:', 'your-plugin-textdomain'),

       'not_found'          => __('No sections found.', 'your-plugin-textdomain'),

       'not_found_in_trash' => __('No sections found in Trash.', 'your-plugin-textdomain'),

   );

   $args = array(

       'labels'             => $labels,
       'public'             => true,
       'publicly_queryable' => true,
       'show_ui'            => true,
       'show_in_menu'       => true,
       'query_var'          => true,
       'rewrite'            => array( 'slug' => 'section' ),
       'capability_type'    => 'post',
       'has_archive'        => true,
       'hierarchical'       => false,
       'menu_position'      => null,

       'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),

   );

   register_post_type('section', $args);

  }

 [space]

Step 2. Add ‘Section’ As A Submenu In Learndash Admin Panel

Once you’re done defining a custom post type for ‘Sections’, you now have to display it under the LearnDash menu, just like Courses, Lessons and Topics.

To do this, just add the code highlighted in black to the register_post_type function used at the end of Step 1.

   );

        register_post_type(‘section’, $args);

  add_submenu_page(‘learndash-lms’, __(‘Section’, ‘your-plugin-textdomain’), ‘Section’, ‘edit_courses’, ‘edit.php?post_type=section’);

}

[space]

Step 3. Placing ‘Section’ Menu Item Under LearnDash

Successfully implementing Step 2 has the downside of adding a menu item called ‘Sections’ in the main Admin menu as shown below:

ld-custom-level

But hey, the fix is simple. To remove this item from the from admin menu and place it under LearnDash menu item, just use the following code snippet:

add_filter('learndash_submenu', 'wdm_add_submenu_lms', 10, 1);

function wdm_add_submenu_lms($addsubmenu)
{

 remove_menu_page('edit.php?post_type=section');
 return $addsubmenu;

}

Here’s how it should look now:

ld-custom-level2

Clicking on Sections takes you to a window that looks like:

ld-custom-level3

The page is just like the ones you have for creating courses, except that this one allows you to create Sections and views the ones you created and saved.

[space]

Step 4. Adding Section Meta Field To Course, Lesson, Topic and Quiz

Here’s where you actually make the associations between Courses, Lessons, Topics and the newly created Sections, establishing the following hierarchy in the process

Section->Course->Lesson->Topic->Quiz

This meta field is used to linking section to course, lesson, topic and quiz. Use the following code:

add_filter('learndash_post_args', 'wdm_add_associate_section_field', 10, 1);

function wdm_add_associate_section_field($post_args)

{

//Adding hierarchy in learndash

   $data =array();

              $args = array(

              'posts_per_page'   => -1,
              'post_type'        => 'section',
              'post_status'      => 'publish'

              );

              $posts_array = get_posts($args);

              $data += ['0' => __('-- Select a Section --', 'your-plugin-textdomain')];

               foreach ($posts_array as $posts_array) {

                   $data += [$posts_array->ID => $posts_array->post_title];

               }

               $vcoursefield = array(

                  'name'=>__('Associated Section', 'your-plugin-textdomain'),

                  'type'=>'select',
                 'initial_options' =>$data,
                  'help_text'=>__('Select section to associate', 'your-plugin-textdomain'),
                  'default' => '0');

               array_unshift($post_args[0]['fields'], $vcoursefield);
               array_unshift($post_args[1]['fields'], $vcoursefield);
               array_unshift($post_args[3]['fields'], $vcoursefield);
               array_unshift($post_args[2]['fields'], $vcoursefield);

               return $post_args;
}

There, you now have successfully created a new course content level in LearnDash, called Sections!

This can also be displayed on the LearnDash profile page. By default, this page displays progress in terms of Courses. But now it would look something like this:

ld-custom-level4

As is evident, the system now recognizes the placement of Sections above Courses in terms of hierarchy and displays progress likewise. In practice, the same can be applied to Quiz reports and User progress.

Happy Learning! :)

Want to bring the same clarity and control to your e-learning platform? Explore our LearnDash customization services to build reporting, analytics, and learner progress features designed around your unique teaching needs.

 

Further Reading on ‘ Growth Hacking with Your LearnDash LMS’

Get a FREE Consultation

Let's build something that lasts.

Share what's on your mind — a clear brief, a half-formed idea, or just a sense that something needs to change. We'll listen first, ask the right questions, and point you toward what's actually worth building.

We take on a handful of projects each quarter,ones where we can truly make a difference.

  • Receive a human response within 24 hours
  • Get a detailed scope and quote upfront
  • We're happy to sign an NDA upon request

    Free 30-Min Strategy Call

    Your Name *

    Your Phone No *

    Work Email *

    Your Budget*

    Project Details *