0

I want to display enrolled courses on a separate page using a shortcode to call the plugin function on the frontend. Which add_shortcode function do I use? Below is the function I am trying to call

$enrolled_course = tutor_utils()->get_enrolled_courses_by_user();
1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Aug 31, 2021 at 9:16

1 Answer 1

1

Step 1 Define your shortcode callback function. You can find some examples for generating the output here.

function your_shortcode_callback( $atts ) {

    // if attributes as used with shortcode, then do something with $atts

    // get data
    $enrolled_course = tutor_utils()->get_enrolled_courses_by_user();

    // do something to turn the data into html string
    $output_html = '';

    // callback should return its output
    return $output_html;
}

Step 2 Register the shortcode. The name can be anything you like as long as it is unique

add_shortcode( 'whatever_you_like_as_shortcode_name', 'your_shortcode_callback' );

Step 3 Use the shortcode

[whatever_you_like_as_shortcode_name]

More details can be found in the Shortcode API Codex entry.

The shortcode callback and registering can be added to a custom plugin or to the theme's functions.php file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.