Skip to content

Instantly share code, notes, and snippets.

@thomasplevy
Created April 15, 2016 02:12
Show Gist options
  • Save thomasplevy/1279be2ac86ccb7293b25252563deceb to your computer and use it in GitHub Desktop.
Save thomasplevy/1279be2ac86ccb7293b25252563deceb to your computer and use it in GitHub Desktop.
Attain sidebar compatibility with just about any theme when using LifterLMS
<?php // do not paste this line into your functions.php
/**
* Display lesson and course custom sidebars on the appropriate LifterLMS pages
*
* @param array $sidebars_widgets array of registered sidebars
* @return array
*/
function lifterlms_sidebar_compatibility( $sidebars_widgets ) {
// replace the widgets in the primary sidebar with LifterLMS Course sidebar on Course Pages
if ( is_singular( 'course' ) && array_key_exists( 'llms_course_widgets_side', $sidebars_widgets ) ) {
// replace "sidebar-1" with your theme's sidebar id
$sidebars_widgets['sidebar-1'] = $sidebars_widgets['llms_course_widgets_side'];
}
// replace the widgets in the primary sidebar with LifterLMS Lesson sidebar on Lesson Pages
elseif ( is_singular( 'lesson' ) && array_key_exists( 'llms_lesson_widgets_side', $sidebars_widgets ) ) {
// replace "sidebar-1" with your theme's sidebar id
$sidebars_widgets['sidebar-1'] = $sidebars_widgets['llms_lesson_widgets_side'];
}
return $sidebars_widgets;
}
add_filter( 'sidebars_widgets', 'lifterlms_sidebar_compatibility' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment