It is really needed to override Learndash Templates sometimes. Thats why I decided to make an article about it.
Ive 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 its 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 itll override the main template.
Where you can find the main template files.
Youll 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, youll need to understand the WordPress hook. If you dont 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 Ive overridden two files. One of them is course.php.
Another one is lesson.php. So youll 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, youll 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 doesnt matter. The matter is youll 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 Its 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 dont 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. Its a free and WordPress repository plugin.
Here is a video from the author of Custom Template For LearnDash Plugin
Feel free to share if youve any issues with this plugin. You can contact us or comment below.
Have a good day 🙂
Tags: how to override Learndash Templates. learndash override templates override learn-boss plugin templates override Learndash Templates.
4 comments
Aadil Mevafarosh
template overriding not working, I used same method mentioned above.
mdtanjid
Hi!
Could you please tell me which template you are trying to override as well as which method you’re following?
Thanks
shefali
My template override is working but unfortunately pagination stopped working.
mdtanjid
Could you please send me your site URL?