Next

How to Customize WP Courses Course and Lesson Templates

WP Courses uses its own templates for course archives, single courses, course category archives, single lessons, teacher archives and single teacher pages.

Templates and template parts for WP Courses can be found in the “templates” and “template-parts” folders respectively.

WP Courses includes these templates using the “template_include” filter.

If you would like to use your own templates you can use the “template_include” filter in you own plugin, theme or functions.php file.

WARNING!

When you create your own template, please begin by copying and pasting all content from the respective default WP Courses template into your custom template.  Lesson tracking is called in the lesson template for example and failing to copy and paste the tracking functionality into your custom template will break lesson tracking.

 

Code 

How to Use Your Own Single Lesson Template

add_filter( 'template_include', 'wpc_my_single_lesson_page_template', 100 );

function wpc_my_single_lesson_page_template( $template ) {
	// only use your custom template if is "lesson" post type and is single
  if ( get_post_type() == 'lesson' && is_single() ) {
		// path to your template
  	$new_template = 'https://mysite.com/wp-content/themes/twentysixteen-child/templates/wpc-my-single-lesson.php';
		// if your template isn't found, use the default template
    if ( !empty( $new_template ) ) {
        return $new_template;
    } 
  } else {
			// if is not "lesson" post type and is not single post, return default template
    	return $template;
  }
}

How to Use Your Own Single Course Template

add_filter( 'template_include', 'wpc_my_single_course_page_template', 100 );

function wpc_my_single_course_page_template( $template ) {
	// only use your custom template if is "course" post type and is single
  if ( get_post_type() == 'course' && is_single() ) {
		// path to your template
  	$new_template = 'https://mysite.com/wp-content/themes/twentysixteen-child/templates/wpc-my-single-course.php';
		// if your template isn't found, use the default template
    if ( !empty( $new_template ) ) {
        return $new_template;
    } 
  } else {
			// if is not "course" post type and is not single post, return default template
    	return $template;
  }
}

How to Use Your Own Archive Course Template

add_filter( 'template_include', 'wpc_archive_course_page_template', 100 );
function wpc_archive_course_page_template( $template ) {
    if ( is_post_type_archive( 'course' )) {
        $new_template = 'https://mysite.com/wp-content/themes/twentysixteen-child/templates/wpc-my-archive-course.php';
        if ( !empty( $new_template ) ) {
            return $new_template;
        } 
    } else {
        return $template;
    }
}

How to Use Your Own Course Category Archive Template

add_filter( 'template_include', 'wpc_my_course_category_page_template', 100 );
function wpc_my_course_category_page_template( $template ) {
    if ( is_tax() == 'course-category' ) {
        $new_template = 'https://mysite.com/wp-content/themes/twentysixteen-child/templates/wpc-my-archive-course.php';
        if ( !empty( $new_template ) ) {
            return $new_template;
        } 
    } else {
        return $template;
    }
}