Shortcode Development

Get Started

Shortcode Development

LearnDash Dashboard registers 9 shortcodes through the Ld<em>Dashboard</em>Shortcodes 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 ld<em>dashboard</em>login<em>notice and ld</em>dashboard<em>login</em>link).
  • Loads templates/ld-dashboard.php (or theme override).
  • Displays role-appropriate tabs and content.

Template: templates/ld-dashboard.php

echo do_shortcode( '[ld_dashboard]' );

[ld<em>instructor</em>registration]

Displays the instructor application/registration form.

Attributes: None (delegates to LD<em>Dashboard</em>Instructor<em>Manager::registration</em>form())

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


[ld<em>dashboard</em>instructors_list]

Displays a paginated, searchable grid of all instructors.

Attributes:

AttributeDefaultDescription
col4Number of grid columns

Filters available:

  • ld<em>dashboard</em>instructors_columns — Modify column count.
  • ld<em>dashboard</em>instructors<em>per</em>page — Items per page (default: 12).
  • ld<em>dashboard</em>instructors<em>list — Filter the instructor WPUser array.
  • ld<em>dashboard</em>instructor_data — Filter individual instructor data.
  • ld<em>dashboard</em>instructor_courses — Filter courses shown per instructor.
  • ld<em>dashboard</em>instructor_avatar — Filter instructor avatar HTML.
  • ld<em>dashboard</em>instructor_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:

  • ld<em>dashboard</em>before<em>single</em>instructor — Fires before single instructor template.
  • ld<em>dashboard</em>after<em>single</em>instructor — Fires after single instructor template.

Templates:

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

[ld<em>student</em>details]

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


[ld<em>enrollment</em>code_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


[ld<em>dashboard</em>meeting]

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


[ld<em>dashboard</em>meeting_single]

Displays a single Zoom meeting detail view.

Attributes:

AttributeDefaultDescription
idMeeting post ID
titleDetailsSection title

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


[ld<em>dashboard</em>meeting_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 ld<em>dashboard</em>is<em>zoom</em>enabled() returns true.


Template Override System

All shortcodes use Ld<em>Dashboard</em>Shortcodes::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 add<em>shortcode during init. You can also extend Ld</em>Dashboard<em>Shortcodes if you need access to locate</em>template().

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