top-arrow

How to override Learndash Templates.

override Learndash Templates

It is really needed to override Learndash Templates sometimes. That’s why I decided to make an article about it.

I’ve divided into two sections.

  • How to override learndash templates from a Child Theme.
  • And how to override its templates from a plugin.

First of all, I would like to discuss.

How to override Learndash Templates from a Child Theme.

If you would like to override Learndash Templates from your child theme, then it’s too easy. Because what you need is to put all templates file into this ‘child-theme/boss-learndash/learndash/ ’ to override Learndash Templates.

So if you put a file from main templates to the following path, then it’ll override the main template.

Where you can find the main template files.

You’ll find main template files in ‘templates/’ directory of your Learndash LMS Plugin.

Finally, I would like to discuss

How to override its Template files from a plugin.
To do that, you’ll need to understand the WordPress hook. If you don’t know what is WordPress hook. Please check out WordPress Codex documentation here.

function replacement_learndash_templates( $filepath, $name, $args, $echo, $return_file_path){
 if ( 'course' == $name ){
   $filepath = plugin_dir_path(__FILE__ ) . 'src/templates/course.php';
 }
 if ( 'lesson' == $name ){
   $filepath = plugin_dir_path(__FILE__) . 'src/templates/lesson.php';
 }
 return $filepath;

}
add_filter('learndash_template','replacement_learndash_templates', 90, 5);

Point to be noted: To override a file you ’ll need to know the exact name of that file.

As you can see that I’ve overridden two files. One of them is ‘course.php’.

Another one is ‘lesson.php’. So you’ll need to make a condition and mention the name of the file in ‘if’ statement as I did above. And make a file in your plugin directory.

Finally, you’ll need to point it out which file you would like to replace with. You can use ‘plugin_dir_path()’ for that.
Most importantly you can name a template file whatever you want, it doesn’t matter. The matter is you’ll have to point out that file as I do.

How to create learndash custom template for lesson

Sometimes we would like to create learndash custom template for lesson in our learndash courses.

So It’s not that difficult to make it. But in accordance with learndash documentation, they strongly suggest us to use a page builder called WPBakery Visual Composer.

Because in accordance with their recommendation using visual composer and learndash is very easy.  You can see the full article here: how to create a custom template for your lesson in learndash courses.

But if you don’t like to use or if you are not ready to use any page builder. 

Then you can use a plugin called Custom Template for LearnDash. It’s a free and WordPress repository plugin.

Here is a video from the author of Custom Template For LearnDash Plugin

Feel free to share if you’ve any issues with this plugin. You can contact us or comment below.

Have a good day 🙂

Tags:

4 comments

1 August, 20197:58 am

template overriding not working, I used same method mentioned above.

2 August, 20195:17 am

Hi!
Could you please tell me which template you are trying to override as well as which method you’re following?

Thanks

6 November, 20199:26 am

My template override is working but unfortunately pagination stopped working.

1 January, 20206:11 pm

Could you please send me your site URL?

Leave a Reply

Mohammad Rahat
about me

Mohammad Rahat Tanjid

Mohammad Tanjid is a professional WordPress Developer and Designer, he builds WP Products like WP Themes/Plugins and author of webextent.net. He has been writing code for more than 5 years now.