How to call a function using a shortcode [closed]

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.