learndash_course_steps_expand_all
Filters whether to expand all course steps on the course topics listing page, defaulting to false.
add_filter( 'learndash_course_steps_expand_all', $callback, 10, 1 );
Description
Allows developers to conditionally control the display of the "Expand All" button within LearnDash course structure templates. Developers can return `false` to hide the button entirely, or modify its visibility based on the provided course ID and context. This hook fires during the rendering of course content, providing an opportunity for custom logic.
Usage
add_filter( 'learndash_course_steps_expand_all', 'your_function_name', 10, 1 );
Parameters
-
$course_id(mixed) - This parameter is a boolean value, likely indicating whether the course steps should be expanded by default.
Return Value
The filtered value.
Examples
<?php
/**
* Example of the 'learndash_course_steps_expand_all' filter.
*
* This filter allows you to programmatically control whether all course steps
* (topics/lessons) are expanded by default on the course listing page.
*
* By default, the 'learndash_course_steps_expand_all' filter returns 'false',
* meaning steps are collapsed by default. This example shows how you could
* force them to be expanded for a specific course or under certain conditions.
*/
add_filter(
'learndash_course_steps_expand_all',
function ( $should_expand, $course_id, $context ) {
// Check if we are in the correct context.
if ( 'course_topics_listing_main' !== $context ) {
return $should_expand; // Return the original value if context doesn't match.
}
// Example: Always expand all steps for a specific course ID (replace 123 with a real course ID).
if ( 123 === absint( $course_id ) ) {
return true; // Force expansion for this course.
}
// Example: Expand all steps if a specific query parameter is present in the URL.
// This is just an illustrative example; consider security and user experience.
if ( isset( $_GET['expand_all_steps'] ) && 'true' === $_GET['expand_all_steps'] ) {
return true; // Force expansion if the query parameter is set.
}
// If none of the above conditions are met, return the original value.
// This will respect the default behavior (collapsed) or any other filters applied.
return $should_expand;
},
10, // Priority: 10 is the default. Adjust if needed.
3 // Accepted args: The filter receives 3 arguments: $should_expand, $course_id, $context.
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/templates/drip-topic-template_legacy.php:107
src/templates/drip-template_legacy.php:107
<div class="expand_collapse">
<a href="#"
onClick='jQuery("#learndash_post_<?php echo $course_id; ?> .learndash_topic_dots").slideDown(); return false;'><?php esc_attr_e( 'Expand All', 'learndash' ); ?></a>
|
<a href="#"
onClick='jQuery("#learndash_post_<?php echo esc_attr( $course_id ); ?> .learndash_topic_dots").slideUp(); return false;'><?php esc_attr_e( 'Collapse All', 'learndash' ); ?></a>
</div>
<?php if ( apply_filters( 'learndash_course_steps_expand_all', false, $course_id, 'course_topics_listing_main' ) ) { ?>
<script>
jQuery(document).ready(function () {
jQuery("#learndash_post_<?php echo $course_id; ?> .learndash_topic_dots").slideDown()
})
</script>
<?php } ?>
<?php endif; ?>