Filter uncanny-toolkit-pro

uo_lesson_topic_grid_template

Filters the template path used for displaying lesson topics in the grid layout.

add_filter( 'uo_lesson_topic_grid_template', $callback, 10, 1 );

Description

Filters the template path used to render a single lesson/topic in the course grid. Developers can override the default template by returning a custom path. This hook fires after initial template path determination, allowing modifications before the template is loaded.


Usage

add_filter( 'uo_lesson_topic_grid_template', 'your_function_name', 10, 1 );

Parameters

$template_path (mixed)
This parameter is the file path to the template used for rendering a single course lesson or topic in a grid.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to modify the lesson/topic grid template path.
 *
 * This filter allows you to change the path to the template file used for
 * displaying individual lessons and topics within a course grid.
 *
 * @param string $template_path The default path to the lesson/topic grid template.
 * @return string The modified path to the lesson/topic grid template.
 */
add_filter( 'uo_lesson_topic_grid_template', 'my_custom_lesson_topic_grid_template', 10, 1 );

function my_custom_lesson_topic_grid_template( $template_path ) {
    // In this example, we'll check if a specific custom template file exists
    // in our theme's directory and use it if available. Otherwise, we'll
    // fall back to the default template.

    // Define the path to your custom template within your theme.
    // It's good practice to put custom templates in a theme subdirectory, e.g., 'template-parts/uncanny-toolkit/'.
    $custom_template_path = trailingslashit( get_stylesheet_directory() ) . 'template-parts/uncanny-toolkit/lesson-topic-grid-custom.php';

    // Check if the custom template file exists.
    if ( file_exists( $custom_template_path ) ) {
        // If it exists, return the path to the custom template.
        return $custom_template_path;
    }

    // If the custom template doesn't exist, return the original template path.
    return $template_path;
}

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/classes/lesson-topic-grid.php:752

private static function course_grid_single( $atts, $lesson_topic_id, $status_icon, $grid_classes, $completed = 'not-completed' ) {
		$course_id = learndash_get_course_id( $lesson_topic_id );
		$user_id   = wp_get_current_user()->ID;
		if ( sfwd_lms_has_access( $course_id, $user_id ) ) {
			$permalink = get_permalink( $lesson_topic_id->ID );
		} elseif ( learndash_is_sample( $lesson_topic_id->ID ) ) {
			$permalink      = get_permalink( $lesson_topic_id->ID );
			$status_icon    = str_replace( esc_html__( 'Not Completed', 'uncanny-pro-toolkit' ), esc_html__( 'Sample Lesson', 'uncanny-pro-toolkit' ), $status_icon );
			$grid_classes[] = 'sample';
		} else {
			$permalink   = 'javascript:;';
			$status_icon = str_replace( esc_html__( 'Not Completed', 'uncanny-pro-toolkit' ), esc_html__( 'Course not enrolled', 'uncanny-pro-toolkit' ), $status_icon );
		}

		$default_no_image_path = plugins_url( '/assets/legacy/frontend/img/no_image.jpg', dirname( __FILE__ ) );
		ob_start();
		$template_path = self::get_template( 'lesson-topic-grid.php', dirname( dirname( __FILE__ ) ) . '/src' );
		$grid_template = apply_filters( 'uo_lesson_topic_grid_template', $template_path );
		include $grid_template;

		return ob_get_clean();
	}

Scroll to Top