LearnDash Hooks Reference
Developer documentation for customizing BuddyX Pro’s LearnDash integration.
Filter Hooks
buddyxldfiltercourseauthor_url
Modify the instructor profile URL on course pages.
add_filter( 'buddyx_ld_filter_course_author_url', 'my_instructor_url', 10, 2 );
function my_instructor_url( $author_url, $instructor_id ) {
// Link to BuddyPress profile instead
if ( function_exists( 'bp_core_get_user_domain' ) ) {
return bp_core_get_user_domain( $instructor_id );
}
return $author_url;
}
Parameters:
$authorurl(string) – Default author posts URL with?posttype=sfwd-courses$instructor_id(int) – User ID of the instructor
Return: String – Modified URL
buddyxldcoursesearchform_format
Control the search form HTML format.
add_filter( 'buddyx_ld_course_search_form_format', 'my_search_format' );
function my_search_format( $format ) {
// Force XHTML format
return 'xhtml';
}
Parameters:
$format(string) – ‘html5’ or ‘xhtml’
Return: String – Format type
getbuddyxldcoursesearch_form
Customize the complete course search form output.
add_filter( 'get_buddyx_ld_course_search_form', 'my_search_form' );
function my_search_form( $form ) {
// Add custom class to form
$form = str_replace( 'class="buddyx_ld_course_search-form',
'class="my-custom-class buddyx_ld_course_search-form',
$form );
return $form;
}
Parameters:
$form(string) – Complete search form HTML
Return: String – Modified form HTML
buddyxlearndashlmsgetcourseparticipantsper_page
Control how many participants show per AJAX load.
add_filter( 'buddyx_learndash_lms_get_course_participants_per_page', 'my_participants_count' );
function my_participants_count( $per_page ) {
// Show 10 participants per page
return 10;
}
Parameters:
$per_page(int) – Default is 5
Return: Integer – Number of participants per page
learndashheadertab_menu
BuddyX Pro uses this LearnDash filter to add custom meta boxes.
add_filter( 'learndash_header_tab_menu', 'my_metaboxes', 15, 4 );
function my_metaboxes( $header_data_tabs, $menu_tab_key, $screen_post_type ) {
// Add custom metabox to Settings tab
foreach ( $header_data_tabs as $key => $data_tabs ) {
if ( 'sfwd-courses-settings' === $data_tabs['id'] ) {
$header_data_tabs[ $key ]['metaboxes'][] = 'my_custom_metabox';
}
}
return $header_data_tabs;
}
Theme-registered metaboxes:
learndashcoursecustom_features– Custom features panel
single_template
BuddyX Pro filters single templates for LearnDash groups.
add_filter( 'single_template', 'my_group_template', 15 );
function my_group_template( $template ) {
if ( get_post_type() === 'groups' ) {
// Use custom template
$my_template = get_stylesheet_directory() . '/my-group-template.php';
if ( file_exists( $my_template ) ) {
return $my_template;
}
}
return $template;
}
Action Hooks
buddyxsubheader
BuddyX Pro replaces the sub header on LearnDash pages.
// Add content before the LearnDash course header
add_action( 'buddyx_sub_header', 'my_before_course_header', 5 );
function my_before_course_header() {
if ( is_singular( 'sfwd-courses' ) ) {
echo 'Enrollment open!';
}
}
Theme modifications:
- Removes default
buddyxsubheaderon single courses/groups - Adds
buddyxlearndashsinglecourseheaderfor courses - Adds
buddyxlearndashsinglegroupheaderfor groups - Adds
buddyxlearndashinstructor_headerfor instructor pages
learndash-focus-header-nav-after
BuddyX Pro adds elements after the Focus Mode header navigation.
add_action( 'learndash-focus-header-nav-after', 'my_focus_button', 15, 2 );
function my_focus_button( $course_id, $user_id ) {
?>
Theme additions at this hook:
- Dark/Light mode toggle (priority 10)
- Sidebar trigger button (priority 10)
pregetbuddyxldcoursesearchform
Fires before the course search form is generated.
add_action( 'pre_get_buddyx_ld_course_search_form', 'my_search_setup' );
function my_search_setup() {
// Custom setup before search form renders
}
save_post
BuddyX Pro saves custom course meta on post save.
add_action( 'save_post', 'my_course_save', 15 );
function my_course_save( $post_id ) {
if ( get_post_type( $post_id ) !== 'sfwd-courses' ) {
return;
}
// Your custom save logic
}
Theme-saved meta:
buddyxldccf_enable– Custom features enabledbuddyxldfeatures– Array of feature icons/textcourseimage_id– Cover image attachment IDgroupimage_id– Group cover image attachment ID
Theme Functions
buddyxlearndashsinglecourseheader()
Renders the Udemy-style single course header.
// Replace with custom header
remove_action( 'buddyx_sub_header', 'buddyx_learndash_single_course_header' );
add_action( 'buddyx_sub_header', 'my_course_header' );
function my_course_header() {
// Custom course header implementation
}
Output includes:
- Breadcrumbs (if enabled)
- Course title
- Short description
- Enrollment count
- Instructor avatars/names
- Last updated date
buddyxlearndashsinglegroupheader()
Renders the single group header.
// Customize group header
remove_action( 'buddyx_sub_header', 'buddyx_learndash_single_group_header' );
add_action( 'buddyx_sub_header', 'my_group_header' );
buddyxlearndashinstructor_header()
Renders the instructor profile header.
// Customize instructor header
remove_action( 'buddyx_sub_header', 'buddyx_learndash_instructor_header' );
add_action( 'buddyx_sub_header', 'my_instructor_header' );
getbuddyxldcoursesearch_form()
Generates the course search form with filters.
// Display in template
if ( function_exists( 'get_buddyx_ld_course_search_form' ) ) {
get_buddyx_ld_course_search_form();
}
// Get form as string
$form = get_buddyx_ld_course_search_form( false );
Parameters:
$echo(bool) – Whether to echo or return (default: true)
Return: String|void – Form HTML when $echo is false
buddyxlearndashldcourseenrolleduserslist()
Get cached count of enrolled users.
$count = buddyx_learndash_ld_course_enrolled_users_list( $course_id );
echo $count . ' students enrolled';
// Force refresh cache
$count = buddyx_learndash_ld_course_enrolled_users_list( $course_id, true );
Parameters:
$course_id(int) – Course ID$force_refresh(bool) – Bypass transient cache (default: false)
Return: Integer – Number of enrolled users
buddyxlearndashfontawesome_icons()
Get array of available FontAwesome icons for course features.
$icons = buddyx_learndash_fontawesome_icons();
// Returns array of icon class names like 'fas fa-book', 'fab fa-youtube', etc.
Return: Array – List of FontAwesome icon class names
AJAX Endpoints
buddyxlearndashlmsgetcourse_participants
AJAX handler for loading more course participants.
Request Parameters:
course(int) – Course IDtotal(int) – Total number of userspage(int) – Current page numbernonce(string) – Security nonce
Response:
{
"success": true,
"data": {
"html": "... ",
"show_more": "true",
"page": 2
}
}
Customizer Settings
Getting Customizer Values
// Category filter enabled
$cat_filter = get_theme_mod( 'ld_category_filter', buddyx_defaults( 'ld-category-filter' ) );
// Instructor filter enabled
$inst_filter = get_theme_mod( 'ld_instructors_filter', buddyx_defaults( 'ld-instructors-filter' ) );
// Course columns
$columns = get_theme_mod( 'ld_cousse_columns', 'default' );
// Values: 'ld_column_1', 'ld_column_2', 'ld_column_3', 'default' (4 columns)
// LearnDash sidebar layout
$sidebar = get_theme_mod( 'ld_sidebar_option', buddyx_defaults( 'ld-sidebar-option' ) );
Post Meta Reference
Course Meta
| Meta Key | Type | Description |
|---|---|---|
buddyxldccf_enable | string | ‘yes’ or empty |
buddyxldfeatures | array | Icon/text pairs |
courseimage_id | int | Cover image ID |
Group Meta
| Meta Key | Type | Description |
|---|---|---|
groupimage_id | int | Cover image ID |
CSS Classes
Course Header Classes
| Class | Element |
|---|---|
.learndash-single-course-header | Main header container |
.course-cover-image | When cover image is set |
.learndash-single-course-header-inner-wrap | Content wrapper |
.course-header-short-description | Description text |
.learndash-course-info | Enrollment info |
.learndash-course-instructor | Instructor section |
.instructor-avatar | Avatar container |
.instructor-name | Name links |
.last-update-date | Update date |
Instructor Header Classes
| Class | Element |
|---|---|
.buddyx-learndash-author-info | Main container |
.lm-course-author-info-tab | Content wrapper |
.lm-course-author-avatar | Avatar container |
.lm-author-bio | Bio section |
.lm-author-title | Name heading |
.lm-author-social | Social links list |
.lm-author-description | Bio text |
Focus Mode Classes
| Class | Element |
|---|---|
.learndash-dark-mode | Dark mode icon |
.learndash-light-mode | Light mode icon |
.ld-focus-sidebar-trigger | Sidebar toggle button |
Template Overrides
Custom Search Form Template
Create buddyxldcourse_searchform.php in your child theme to override the search form.
// child-theme/buddyx_ld_course_searchform.php
Custom Group Template
Create single-sfwd-groups.php in your child theme for custom group single template.
Related Documentation
- README – Technical overview
- Customer Guide – Setup instructions
- Developer Hooks – All theme hooks
