uo_course_grid_ribbon_text
Filters the text displayed on course grid ribbons, allowing customization before rendering.
add_filter( 'uo_course_grid_ribbon_text', $callback, 10, 2 );
Description
Filters the text displayed on course grid ribbons. Use this hook to customize the default ribbon text, such as 'Closed' or the course price, based on course status or other criteria. The hook receives the current ribbon text and the course ID as parameters.
Usage
add_filter( 'uo_course_grid_ribbon_text', 'your_function_name', 10, 2 );
Parameters
-
$output(mixed) - This parameter contains the HTML string that will be displayed as the ribbon text on the course grid.
-
$course(mixed) - This parameter contains the HTML-escaped text that will be displayed as the course ribbon.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Modify the course ribbon text to display a custom message for free courses.
*
* This filter hook allows you to customize the text displayed on the course grid
* ribbon. In this example, we check if a course is free and, if so, change the
* ribbon text to "Free Course".
*
* @param string $output The default ribbon text.
* @param int $course_id The ID of the current course.
* @return string The modified ribbon text.
*/
add_filter( 'uo_course_grid_ribbon_text', function( $output, $course_id ) {
// Check if the course is actually free.
// This is a placeholder for how you might determine if a course is free.
// You'll need to adapt this logic based on how your WordPress site
// manages course pricing and free status. For example, you might check
// post meta, a custom field, or an LMS plugin's specific functions.
$is_free_course = false;
// Example: Assuming a post meta key '__is_free_course' exists and is 'yes' for free courses.
if ( get_post_meta( $course_id, '_is_free_course', true ) === 'yes' ) {
$is_free_course = true;
}
if ( $is_free_course ) {
$output = esc_html__( 'Free Course', 'your-text-domain' );
}
return $output;
}, 10, 2 );
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:65
$output = esc_attr__( 'Closed', 'uncanny-pro-toolkit' );
break;
default:
$output = esc_html( $course_price_type );
break;
}
echo wp_kses_post( apply_filters( 'uo_course_grid_ribbon_text', $output, $course->ID ) );
do_action( 'uo_course_after_grid_ribbon_text', $course->ID );
} else {
echo wp_kses_post( apply_filters( 'uo_course_grid_ribbon_price', $course_price, $course->ID ) );
do_action( 'uo_course_after_grid_ribbon_price', $course->ID );
}
?>