Shortcode Development

Get Started

Shortcode Development

LearnDash Dashboard registers 9 shortcodes through the LdDashboardShortcodes singleton. All shortcodes use output buffering and support theme template overrides.


Available Shortcodes

[ld_dashboard]

Renders the main frontend dashboard panel.

Attributes: None

Behavior:

  • Shows a login notice and link for logged-out users (filterable via lddashboardloginnotice and lddashboardloginlink).
  • Loads templates/ld-dashboard.php (or theme override).
  • Displays role-appropriate tabs and content.

Template: templates/ld-dashboard.php

echo do_shortcode( '[ld_dashboard]' );

[ldinstructorregistration]

Displays the instructor application/registration form.

Attributes: None (delegates to LDDashboardInstructorManager::registrationform())

Behavior: Shows the registration form to non-instructors. Logged-in instructors see a message that they are already registered.


[lddashboardinstructors_list]

Displays a paginated, searchable grid of all instructors.

Attributes:

AttributeDefaultDescription
col4Number of grid columns

Filters available:

  • lddashboardinstructors_columns — Modify column count.
  • lddashboardinstructorsperpage — Items per page (default: 12).
  • lddashboardinstructorslist — Filter the instructor WPUser array.
  • lddashboardinstructor_data — Filter individual instructor data.
  • lddashboardinstructor_courses — Filter courses shown per instructor.
  • lddashboardinstructor_avatar — Filter instructor avatar HTML.
  • lddashboardinstructor_name — Filter instructor display name.

If the URL matches an instructor profile (via instructor_username query var), a single instructor profile is shown instead of the grid.

Actions:

  • lddashboardbeforesingleinstructor — Fires before single instructor template.
  • lddashboardaftersingleinstructor — Fires after single instructor template.

Templates:

  • Grid: No template file (inline output).
  • Single profile: templates/ld-dashboard-single-instructor.php.

[ldstudentdetails]

Displays student progress details. Visible to instructors, group leaders, and administrators only.

Attributes: None

Template: templates/ld-dashboard-student-status.php


[ld_email]

Displays the email integration interface for sending bulk emails to students.

Attributes: None

Visibility: Only shown when the enable-email-integration general setting is enabled and the user is an instructor, group leader, or administrator.

Template: templates/ld-dashboard-email-integration.php


[ldenrollmentcode_redeem]

Displays an enrollment code redemption widget for logged-in users.

Attributes: None

Behavior: Returns empty string for logged-out users. Enqueues ld-dashboard-enrollment-codes style and script.

Template: templates/dashboard-widgets/enrollment-code-redeem.php


[lddashboardmeeting]

Displays a list of Zoom meetings. Requires the Zoom module to be active.

Attributes:

AttributeDefaultDescription
idMeeting post ID
titleDetailsSection title

Template: templates/ld-dashboard-meeting-shortcode.php


[lddashboardmeeting_single]

Displays a single Zoom meeting detail view.

Attributes:

AttributeDefaultDescription
idMeeting post ID
titleDetailsSection title

Template: templates/ld-dashboard-single-meeting.php


[lddashboardmeeting_embed]

Embeds a Zoom meeting via iframe or SDK.

Attributes:

AttributeDefaultDescription
meeting_idZoom meeting ID
height500pxFrame height
iframeyesEnable iframe embed
disable_countdownnoDisable pre-join countdown

Zoom shortcodes only render when lddashboardiszoomenabled() returns true.


Template Override System

All shortcodes use LdDashboardShortcodes::locate_template() to find templates. The lookup order is:

  1. Active child theme: {child-theme}/ld-dashboard/{template-name}
  2. Active parent theme: {parent-theme}/ld-dashboard/{template-name}
  3. Plugin: {plugin}/templates/{template-name}

To override a template, copy it from the plugin’s templates/ directory to your theme’s ld-dashboard/ directory.

mytheme/
└── ld-dashboard/
    └── ld-dashboard.php          # Overrides main dashboard template
    └── ld-dashboard-student-status.php

Output Buffering Pattern

All shortcode render methods use WordPress’s recommended output buffering pattern:

public function render_my_shortcode( $atts, $content = '' ) {
    ob_start();

    // Template or inline output.
    $template = $this->locate_template( 'my-template.php' );
    if ( $template ) {
        include $template;
    }

    return ob_get_clean();
}

This ensures shortcodes return HTML rather than echo it directly, which is required for correct WordPress shortcode behavior.


Permission Checks

Shortcodes perform role checks before rendering content:

// Check if user is an instructor, group leader, or admin.
if (
    ! learndash_is_group_leader_user()
    && ! learndash_is_admin_user()
    && ! LD_Dashboard_Helper::is_instructor()
) {
    return ''; // Return empty for students.
}

The [ld_dashboard] shortcode shows a login prompt for logged-out users rather than returning empty.


Adding Custom Shortcodes

You can add custom shortcodes that integrate with the dashboard’s template system by hooking into WordPress’s addshortcode during init. You can also extend LdDashboardShortcodes if you need access to locatetemplate().

add_action( 'init', function() {
    add_shortcode( 'my_dashboard_widget', function( $atts ) {
        // Only for logged-in users.
        if ( ! is_user_logged_in() ) {
            return '';
        }

        $atts = shortcode_atts(
            array( 'title' => __( 'My Widget', 'my-plugin' ) ),
            $atts
        );

        ob_start();

        // Check theme override first.
        $theme_template = get_stylesheet_directory() . '/ld-dashboard/my-widget.php';
        $plugin_template = MY_PLUGIN_DIR . 'templates/my-widget.php';

        if ( file_exists( $theme_template ) ) {
            include $theme_template;
        } elseif ( file_exists( $plugin_template ) ) {
            include $plugin_template;
        }

        return ob_get_clean();
    } );
} );

Within your template file, you have access to $atts (shortcode attributes) and all standard WordPress globals.

Last updated: March 4, 2026