Browse: Home / Snippets /

Shortcode to display the first Group Leader of a Course’s associated Group on the Certificate


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

Usage: Place the shortcode [group_leader] in the certificate.

function learndash_course_group_leader_shortcode() {
   $course_id = get_post_meta(get_the_ID(), 'course_id', true) ?: learndash_get_course_id();
   $group_ids = learndash_get_course_groups($course_id);
   if (empty($group_ids)) {
       return 'No Group Leader Assigned';
   }
    foreach ($group_ids as $group_id) {
       $group_leader_objects = learndash_get_groups_administrators($group_id);

        if (empty($group_leader_objects)) {
           continue;
         }

     foreach ($group_leader_objects as $group_leader) {
        if (!is_a($group_leader, 'WP_User')) {
            continue;
        }

        return esc_html($group_leader->display_name);
    }
}

return 'No Group Leader Assigned';
}
add_shortcode('group_leader', 'learndash_course_group_leader_shortcode');