LMS & eLearning

Adding a Tab to LearnDash Admin Pages With learndash_admin_tabs_set

How the tab bar across LearnDash admin screens is assembled, the legacy learndash_admin_tabs filter versus the learndash_admin_tabs_set action, and how to add, reorder or hide a tab by capability.

Adding a Tab to LearnDash Admin Pages With learndash_admin_tabs_set

Across the LearnDash admin, every post type screen carries a row of tabs: Courses, Course Builder, Settings, Categories and so on, and the Quizzes screen adds Submitted Essays, which is a different post type altogether. Those tabs are not WordPress submenus; they are built by LearnDash's menus and tabs class and can be extended so that your own admin page appears as a tab in the right place, with the right capability, next to LearnDash's. This guide explains how the tab sets are assembled in LearnDash 4.18.0.1, the modern action and the legacy filter for adding tabs, and how to adjust or remove existing ones. For adding settings rather than a page, see our guide to custom LearnDash settings sections.

How tab sets are built

The class Learndash_Admin_Menus_Tabs keeps an array of tab sets keyed by menu slug, where a menu slug is the parent screen such as edit.php?post_type=sfwd-courses or admin.php?page=learndash_lms_settings. Each set is an array of tab items keyed by priority. On each admin page load the class works out the current screen's parent file, builds LearnDash's own items for that set, and then gives you two opportunities to change it. First it fires the action learndash_admin_tabs_set with the current parent file and the class instance, which is where you add tabs. Then, when rendering, it passes the set through the filter learndash_admin_tab_sets( $tab_set, $menu_tab_key, $current_page_id ), which is where you reorder or remove. A third, older filter, learndash_admin_tabs, returns a flat array of legacy items and is still honoured for compatibility.

The tab item

A tab item is an array with link, the admin URL relative to wp-admin; name, the label; id, a unique identifier the class compares with the current page to mark the active tab; cap, the capability required to see it, defaulting to LEARNDASH_ADMIN_CAPABILITY_CHECK when omitted; and optionally parent_menu_link when the page lives under a different parent than the set, which is how Submitted Essays appears under Quizzes while being its own post type. Items are added with add_admin_tab_item( $menu_slug, $menu_item, $menu_priority ); if the priority is taken, the class increments until it finds a free slot, so collisions never drop a tab.

Adding a tab with the action

Suppose you registered an admin page with add_submenu_page() under the Courses menu at slug acme-course-reports. To show it as a tab on every Courses screen:

<?php
add_action(
    'learndash_admin_tabs_set',
    function ( $current_screen_parent_file, $tabs ) {
        if ( 'edit.php?post_type=sfwd-courses' !== $current_screen_parent_file ) {
            return;
        }

        $tabs->add_admin_tab_item(
            'edit.php?post_type=sfwd-courses',
            array(
                'link' => 'edit.php?post_type=sfwd-courses&page=acme-course-reports',
                'name' => 'Reports',
                'id'   => 'sfwd-courses_page_acme-course-reports',
                'cap'  => 'edit_courses',
            ),
            40
        );
    },
    10,
    2
);

The id should equal the screen ID WordPress assigns to your page, which for a submenu under a post type is {post_type}_page_{slug}; that is how the class highlights your tab when the page is open. The priority of 40 places the tab after LearnDash's own items, which use lower numbers. For a page that should appear on both the Courses and Groups screens, call the action handler for both parent files and add the item to both sets with the same link.

The legacy filter

Older code adds tabs through learndash_admin_tabs, returning an array of items with id, name, link and menu_link, where menu_link is the parent screen. The class still reads it and even rewrites the old settings parent link to the current one. It works, but it runs before the sets exist, lacks priorities and offers no instance to call methods on, so prefer the action for new code. If you maintain a plugin that uses the filter, it will keep working in 4.18.0.1.

Reordering and removing

The learndash_admin_tab_sets filter receives one set at a time, with the menu key and current page ID, after LearnDash and your action have added items. Because the set is keyed by priority, reordering means moving items to new keys, and removing means unsetting. The following hides the Course Builder tab for a custom role that should edit course content but not its outline, and moves the Reports tab added above to the front:

<?php
add_filter(
    'learndash_admin_tab_sets',
    function ( $tab_set, $menu_tab_key, $current_page_id ) {
        if ( 'edit.php?post_type=sfwd-courses' !== $menu_tab_key ) {
            return $tab_set;
        }

        foreach ( $tab_set as $priority => $item ) {
            if ( ! isset( $item['id'] ) ) {
                continue;
            }

            if ( 'sfwd-courses_page_acme-course-reports' === $item['id'] ) {
                unset( $tab_set[ $priority ] );
                $tab_set[1] = $item;
            }

            if ( current_user_can( 'acme_content_editor' ) && 'learndash_course_builder' === $item['id'] ) {
                unset( $tab_set[ $priority ] );
            }
        }

        ksort( $tab_set );
        return $tab_set;
    },
    10,
    3
);

Match on the item's id rather than its label, since labels are translated and follow custom labels. Read the existing IDs by dumping the set once with a temporary error_log( wp_json_encode( $tab_set ) ) inside the filter.

Capabilities and group leaders

Group leaders see the LearnDash menu through their own capability, and LearnDash chooses the parent menu accordingly: for the essays tab it uses LEARNDASH_GROUP_LEADER_CAPABILITY_CHECK and a parent_menu_link of learndash-lms when the current user is a leader. If your tab should appear for leaders, give it a capability they hold, such as group_leader, and set parent_menu_link to the menu they actually see; otherwise the tab is hidden for them even if the page is accessible. Our group leader role guide lists the capabilities.

When to get help

Adding a tab is an hour's work with the action above. Full admin modules with their own list tables, exports and leader-scoped data behind that tab are development projects our LearnDash services team and LearnDash development practice build, and a LearnDash developer can also consolidate several plugin pages into one coherent LearnDash tab set.

Frequently asked questions

Which hook adds a tab to LearnDash admin pages?

The action learndash_admin_tabs_set, which passes the current parent screen and the tabs object; call add_admin_tab_item() on it. The older learndash_admin_tabs filter still works.

Why is my tab never highlighted?

The item's id must match the page's screen ID, for example sfwd-courses_page_my-slug for a submenu page under Courses.

How do I remove a LearnDash tab?

Unset it in the learndash_admin_tab_sets filter by matching its id, optionally only for certain capabilities.

Can group leaders see my tab?

Only if its cap is one they hold and its parent_menu_link points to the menu they see, as LearnDash does for the essays tab.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.