Adding Custom Tab at Course Edit Page in LearnDash

Are you looking to enhance your LearnDash menu by adding submenus? Look no further. In this guide, we’ll show you how to achieve this by using WordPress hooks and the technique of adding a custom tab.

First, we’ll use the admin_menu hook to seamlessly integrate our submenu. This hook allows us to tap into WordPress’s administrative menu system, enabling us to extend it with our custom submenu.

Let’s dive into the code and see how the admin_menu hook can help us.

In WordPress, hooks are crucial connection points that allow developers to execute custom code at specific times. The admin_menu hook is triggered when the administrative menu is being constructed. Within its callback function, we’ll use the add_submenu_page() function to add our custom tab. This function requires several parameters:

 

  • $parent_slug (string, required): The slug name for the parent menu or the file name of a standard WordPress admin page.
  • $page_title (string, required): The text displayed in the title tags of the page when the menu is selected.
  • $menu_title (string, required): The text used for the submenu.
  • $capability (string, required): The capability required for this menu to be displayed to the user.
  • $menu_slug (string, required): The slug name to refer to this menu by. It should be unique and consist only of lowercase alphanumeric characters, dashes, and underscores.
  • $callback (callable, optional): The function responsible for outputting the content for this page.
  • $position (int|float, optional): The position in the menu order this item should appear.

By effectively leveraging these parameters, you can seamlessly integrate your custom tab into the LearnDash menu, offering users a cohesive and intuitive navigation experience.

By effectively leveraging these parameters, you can seamlessly integrate your custom tab into the LearnDash menu, offering users a cohesive and intuitive navigation experience.

				
					if( 'sfwd-topic' != $screen_post_type && 'sfwd-quiz' != $screen_post_type && 'sfwd-lessons' !=     $screen_post_type  && 'sfwd-courses' != $screen_post_type ) {
    return $header_tabs_data;
}

				
			

Step 2: Adding Tabs

Next, we proceed to add our custom tabs. Each tab is represented by an array containing its ID, name, and associated metabox ID. This information is appended to the existing array of tab data.

				
					$header_tabs_data[] = [

    'id'        => 'tab_id',
    'name'      => 'Tab Name',
    'metaboxes' => ['metabox-id']
];

				
			

Here, ‘tab_id’ represents the unique identifier for the tab, ‘Tab Name’ is the display name of the tab, and ‘metabox-id’ refers to the metabox ID where the tab’s content will reside.

Step 3: Implementing the Code

To execute the code, we utilize the ‘add_filter’ and ‘add_action’ functions. The ‘learndash_header_tab_menu’ filter enables us to modify the tab menu, while the ‘add_meta_boxes’ action is used to add the corresponding metabox.

				
					add_filter( 'learndash_header_tab_menu', 'lt_add_custom_tabs', 10, 3 );
function lt_add_custom_tabs( $header_tabs_data, $menu_tab_key, $screen_post_type ) {

    if( 'sfwd-topic' != $screen_post_type && 'sfwd-quiz' != $screen_post_type && 'sfwd-lessons' != $screen_post_type  && 'sfwd-courses' != $screen_post_type ) {

        return $header_tabs_data;
    }

$header_tabs_data[] = [

    'id'        => 'tab_id',
    'name'      => 'Tab Name',
    'metaboxes' => ['metabox-id']
];

return $header_tabs_data;

}

add_action( 'add_meta_boxes', 'lt_add_metabox', 10, 2 );

function lt_add_metabox( $post_type, $post ) {

        if( 'sfwd-courses'      != $post_type
        && 'sfwd-lessons'   != $post_type
        && 'sfwd-topic'     != $post_type
        && 'sfwd-quiz'      != $post_type ) {
    
            return false;
    }

    add_meta_box(
    
        'metabox-id',
        'metabox heading',
        'lt_customtabs_metabox_content',
        $post_type,
        'advanced',
        'high'
    );
}

function lt_customtabs_metabox_content() {
    echo 'content';
}

				
			

Conclusion:

By following these steps and implementing the provided code snippets, you can seamlessly integrate tabs into the edit pages of courses, lessons, topics, or quizzes in LearnDash. This enhances the organization and accessibility of content, contributing to a more user-friendly editing experience.

not found

Leave a Comment

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

Scroll to Top