Template System

LearnPress uses a template system similar to WooCommerce, allowing theme developers to customize the appearance of LearnPress content.

Template Structure

The template files are organized in the templates/ directory of the LearnPress plugin:

learnpress/
└── templates/
├── content-lesson.php
├── content-quiz.php
├── content-single-course.php
├── single-course/
│ ├── content.php
│ ├── curriculum.php
│ ├── instructor.php
│ ├── price.php
│ └── …
├── single-lesson/
│ └── …
├── single-quiz/
│ └── …
└── profile/
└── …

Template Customization Methods

There are two primary methods to customize LearnPress templates:

1. Template Override in Theme

This is the recommended approach for extensive customizations:

  1. Create a learnpress directory in your theme
  2. Copy the template files you want to customize from the plugin’s templates/ directory to your theme’s learnpress/ directory, maintaining the same file structure
  3. Modify the copied templates as needed
# Example: To override the course curriculum template
# Copy from:
wp-content/plugins/learnpress/templates/single-course/curriculum.php
# To:
wp-content/themes/your-theme/learnpress/single-course/curriculum.php

LearnPress will automatically use your theme’s template files instead of the plugin’s default templates.

2. Using Hooks and Filters

For smaller customizations, you can use LearnPress’s extensive hook system without copying entire template files. This approach is more update-safe but will be covered in detail in a separate section.

Template Loading Process

LearnPress follows this hierarchy when loading templates:

  1. First, it checks for a template in the child theme (if active): /wp-content/themes/your-child-theme/learnpress/
  2. Next, it checks the parent theme: /wp-content/themes/your-theme/learnpress/
  3. Finally, it falls back to the plugin’s default templates: /wp-content/plugins/learnpress/templates/

This system allows for flexible customization while maintaining compatibility with plugin updates.

Template Functions

LearnPress provides several helper functions for working with templates:

  • learn_press_get_template() – Loads a specific template file
  • learn_press_get_template_part() – Loads a template part, similar to WordPress’s get_template_part()
  • learn_press_locate_template() – Locates a template file in the theme or plugin

These functions handle the template hierarchy and make it easier to work with LearnPress templates in your custom code.