Filter uncanny-toolkit-pro

uo_lesson_topic_grid_view_style

Filters the CSS file URL for the lesson topic grid view, allowing customization of its styling.

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

Description

Filters the URL for the CSS file enqueued for the lesson and topic grid view. This allows developers to modify the stylesheet path or conditionally enqueue different styles based on specific criteria. It's applied before the core stylesheet is loaded, providing a way to override or augment its presentation.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Filter to modify the lesson/topic grid view CSS file.
 *
 * This function allows developers to hook into the process of enqueuing
 * the CSS file for the lesson and topic grid view. They can return a
 * different CSS file path to override the default styles.
 *
 * @param string $css_file_url The default URL of the lesson-topic-grid-view.css file.
 * @return string The URL of the CSS file to be enqueued.
 */
add_filter( 'uo_lesson_topic_grid_view_style', 'my_custom_lesson_topic_grid_css', 10, 1 );

function my_custom_lesson_topic_grid_css( $css_file_url ) {
	// Check if we are on a specific page or post type where custom styling is needed.
	// For example, let's say we want to apply a different stylesheet for pages
	// with a specific meta key set to 'true'.
	global $post;

	if ( $post && get_post_meta( $post->ID, '_my_custom_grid_style', true ) === 'true' ) {
		// Return a URL to a custom CSS file if the condition is met.
		// Make sure this file exists within your theme or plugin.
		return get_stylesheet_directory_uri() . '/css/custom-lesson-topic-grid-styles.css';
	}

	// Otherwise, return the original CSS file URL.
	return $css_file_url;
}

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:192

public static function uo_grid_view_style() {

		global $post;

		if ( empty( $post->ID ) ) {
			return;
		}

		if (
			! has_shortcode( $post->post_content, 'uo_lessons_topics_grid' )
			&& ! has_block( 'uncanny-toolkit-pro/lesson-topic-grid', $post )
			&& ! in_array( $post->post_type, array( 'sfwd-courses', 'sfwd-lessons' ), true )
		) {
			return;
		}

		wp_enqueue_style( 'course-grid-view-core', plugins_url( '/assets/legacy/frontend/css/course-grid-view-core.css', dirname( __FILE__ ) ), array(), UNCANNY_TOOLKIT_PRO_VERSION );
		$grid_view_css = apply_filters( 'uo_lesson_topic_grid_view_style', plugins_url( '/assets/legacy/frontend/css/lesson-topic-grid-view.css', dirname( __FILE__ ) ) );
		wp_enqueue_style( 'lesson-topic-grid-view', $grid_view_css, array(), UNCANNY_TOOLKIT_PRO_VERSION );
	}

Scroll to Top