uo_course_grid_start_button
Filters the HTML output for the "Start Course" button on the course grid, allowing customization before it displays.
add_filter( 'uo_course_grid_start_button', $callback, 10, 1 );
Description
Filters the HTML for the "Start Course" button displayed in the course grid. Developers can modify the button's appearance, text, or add/remove attributes before it's output. Useful for customizing the call to action for each course based on course data or permalink.
Usage
add_filter( 'uo_course_grid_start_button', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example filter for the uo_course_grid_start_button hook.
* This example adds a custom class to the start button if the course has a specific tag.
*
* @param string $start_button_html The original HTML for the start button.
* @param object $course The current course object.
* @param string $permalink The permalink to the course.
* @return string The modified start button HTML.
*/
add_filter( 'uo_course_grid_start_button', function( $start_button_html, $course, $permalink ) {
// Check if the course object and its ID are available.
if ( ! $course || ! isset( $course->ID ) ) {
return $start_button_html;
}
// Define a custom tag to look for.
$custom_tag = 'premium-course';
// Check if the course has the specified tag.
if ( has_term( $custom_tag, 'course-tag', $course->ID ) ) {
// If the tag exists, add a custom class to the button.
// This assumes the $start_button_html is a string containing an HTML element.
// A more robust solution might involve DOM manipulation if the structure is complex.
$start_button_html = str_replace( '<a href', '<a class="premium-course-button" href', $start_button_html );
}
return $start_button_html;
}, 10, 3 ); // Priority 10, accepts 3 arguments.
?>
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/course-grid.php:230
$start_button_html,
$course,
$permalink,
),
'3.7.11',
'uo_course_grid_start_button'
);
echo apply_filters( 'uo_course_grid_start_button', $start_button_html, $course, $permalink );
}
?>
<?php
if ( 'show' === $show_resume_button && $percentage > 0 && $percentage < 100 ) {
$uo_active_classes = get_option( 'uncanny_toolkit_active_classes', 0 );
if ( is_array( $uo_active_classes ) && ! empty( $uo_active_classes ) ) {