LearnDash ProTips: Adding A Custom Course Level

    Suraj M
Listen to this article
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);



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’);



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:


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)

 return $addsubmenu;


Here’s how it should look now:


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


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.


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


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'),

                 '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:


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! 🙂

Suraj M

Suraj M

11 Responses

  1. HI There,

    Excellent work in getting this up and running! It will come in very handy for me… i do have a couple of questions so hoping you can assist 🙂

    1. Are all steps in the one php file? (plugin_name.php) in your example?
    2. Will i be able to assign a Course to multiple Sections?

    Thanks again and good job.

    1. Hey Christopher,


      Here are the answers to your questions:

      1. Yes, all the steps have to be added in one file.
      2. No. With the current code, you will not be able to assign a course to multiple sections.


      1. Thank you for your response Suraj,

        I am unable to replicate your instructions and get it to work as 1 file and have also done a few hours trying to troubleshoot to the best of my beginner PHP ability…

        When i first activated the plugin it instantly gave me errors for the last few lines where the array_unshift is. (I used your beginners guide to making plugins, thanks for that as well!)

        I have worked through all the errors and i can assign the Section in the course page, but there is no further linkage than that and i dont get any course progress or additional fields in the Section pages.

        Could you please send me it in a zip so i can learn where i have gone wrong and also know what the end output is?

        Thanks again for your time.

        1. Hi Christopher,

          I’m glad to hear you were successfully able to set up a Section. To see the Section Progress on the profile page as well as the fields on the Single Section page would require extensively modifying the templates for the same.

          This is actually a part of a project we undertook, I’m afraid I wouldn’t be able to give out the zip file or the code at present, as agreed upon with the client. However, feel free to contact us should you want to enlist our services for the development. 🙂

  2. hi suraj-

    like ahmed, i am interested in how this plugin code could be modified so that instead of creating a “section” that sits higher than all the other learndash post types the sections actually become a new sub-level of a topic. is that a simple change or would that be complex?

    alternately, when i followed your instructions and activated the plugin on my wordpress site a weird “sfwd” custom post type appeared in the admin sidebar. it seemed to have an options panel and the same formatting for adding and organizing the custom post types. is that something that you experience too?

  3. Hello. Please some help because i dont know what is failing……
    I followed the instructions carefully (twice).
    I created a custom plugin with the code….
    I have the Custom Post Type “Sections” inside LearnDash Admin Menu.
    Im able to create differents Sections

    But im not able to link the course with the section.
    In the course editor there isn´t any meta box with “Sections”.

    Something is not right, because i have a new menu item called “SFWD CPT Instance” that i cannot remove…..

    Im using WordPress 4.9.2 and LearndDash 2.5.4
    Does the code still working on these versions?

  4. Dear Support,

    I followed the Steps on this page and created the Plugin which seems to be partially working.
    I’m having an issue with the last Step “Section->Course->Lesson->Topic->Quiz”.
    As soon as I paste the Code in my PHP plugin file, I get the following Error:

    Warning: array_unshift() expects parameter 1 to be array, null given in /wp-content/plugins/learndash-sections/learndash_sections.php on line 122, line 123, line 124 and line 125

    Those lines reflect on the following code
    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);

    What can I do, to fix this issue?

    System Info:
    Wordpress 5.2.1
    Learndash LMS 2.6.6
    PHP Version 7.2.18

    Thank you in advance

Leave a Reply

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

Get The Latest Updates

Subscribe to our Newsletter

A key to unlock the world of open-source. We promise not to spam your inbox.

Suggested Reads

Join our 55,000+ Subscribers

    The Wisdm Digest delivers all the latest news, and resources from the world of open-source businesses to your inbox.

    Suggested Reads