How to Easily Display Course ID in LearnDash Admin Panel?

Do you want to display the course ID in the LearnDash admin panel on the courses screen?

By default, the LearnDash courses admin area displays columns like Course Title, Price Type, Author, and Date. While useful, there are times when having the Course ID readily available can save you from extra steps.

Typically, if you need a Course ID, you’d have to edit each course individually and retrieve the ID manually—a process that’s both time-consuming and inefficient.

A better solution is to add a dedicated admin column that displays the Course ID directly in the LearnDash courses screen. This simple enhancement makes managing your courses easier and more streamlined, especially when working with shortcodes, custom development, or troubleshooting.

Why Show Course ID Admin Column in LearnDash Courses?

Displaying the course ID in the LearnDash admin panel can be beneficial for several reasons:

1. Easier Course Management:

If you manage multiple courses, it can become difficult to distinguish them based solely on the course titles, especially if they are similar. Showing the Course ID provides a unique identifier for each course, simplifying course management.

2. Quick Reference for Shortcodes or API:

Some LearnDash shortcodes and API calls require the Course ID to function correctly. Having the Course ID readily available in the admin panel makes it easy to reference when you’re adding shortcodes to posts, pages, or custom templates.

3. Developer Convenience:

For developers or site administrators who work with custom code, integrations, or third-party tools, accessing the Course ID directly from the admin panel speeds up workflows without needing to dig into the database or inspect page elements.

4. Enhanced Reporting and Debugging:

When generating reports or debugging course-related issues, the Course ID is often required. Having it visible in the admin panel can help in faster troubleshooting.

5. Consistency with Other Post Types:

WordPress often displays the post or page ID in admin columns, so showing the course ID can keep the interface consistent and intuitive for users familiar with other post types.

Adding the Course ID column is a simple yet useful improvement for both site administrators and developers managing LearnDash-based e-learning platforms.

How to Show Course ID Admin Column in LearnDash Courses?

Use the code snippet below to show the course ID admin column in LearnDash Courses.

php
/**
 * Add course ID admin column labels to LearnDash courses admin area
 *
 * @param array $columns
 * @return array $columns
 */
function maverick_add_learndash_course_id_admin_column_labels($columns)
{
    $columns['course_id'] = __('Course ID');

    return $columns;
}

add_filter('manage_sfwd-courses_posts_columns', 'maverick_add_learndash_course_id_admin_column_labels');

/**
 * Add course ID admin column to LearnDash courses admin area
 *
 * @param string $column
 * @param int $post_id
 */
function maverick_add_learndash_course_id_admin_columns($column, $post_id)
{
    switch ($column) {
        case 'course_id':
            echo $post_id;
            break;
    }
}

add_action('manage_sfwd-courses_posts_custom_column', 'maverick_add_learndash_course_id_admin_columns', 10, 2);

Leave a Reply

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