uo_course_before_short_description
Fires before the course's short description is displayed, allowing modification of course data.
add_action( 'uo_course_before_short_description', $callback, 10, 1 );
Description
Fires before the course short description is displayed in the course grid. Developers can use this action to add custom content or modify the output before the short description appears, such as displaying additional course details or integrating third-party elements. It passes the course ID as a parameter.
Usage
add_action( 'uo_course_before_short_description', 'your_function_name', 10, 1 );
Parameters
-
$course(mixed) - This parameter contains the ID of the current course object.
Examples
<?php
/**
* Example callback function for the 'uo_course_before_short_description' action hook.
* This function will output additional information about the course before its short description.
*
* @param int $course_id The ID of the current course.
*/
function my_custom_course_info_before_description( $course_id ) {
// Check if the course ID is valid.
if ( ! $course_id || ! is_numeric( $course_id ) ) {
return;
}
// Get custom fields or post meta related to the course.
// For example, let's assume we have a custom field for 'course_level'.
$course_level = get_post_meta( $course_id, 'course_level', true );
// Only output if a course level is set.
if ( ! empty( $course_level ) ) {
echo '<div class="course-level-display">';
echo '<span class="label">Level:</span> ';
echo esc_html( ucfirst( $course_level ) ); // Display the course level, capitalized.
echo '</div>';
}
// You could also add other dynamic content here, like:
// - Displaying the instructor's name (if stored separately)
// - Showing the number of enrolled students (if available)
// - Adding a link to a "Read More" page if the description is truncated
}
// Add the callback function to the 'uo_course_before_short_description' action hook.
// The '10' is the default priority, and '1' indicates that the function accepts one argument.
add_action( 'uo_course_before_short_description', 'my_custom_course_info_before_description', 10, 1 );
?>
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:140
</p>
<?php
}
}
?>
<!-- Course description - Start -->
<div
class="course-before-short-description"><?php do_action( 'uo_course_before_short_description', $course->ID ); ?></div>
<?php
if ( ( 'no' === $atts['hide_description'] ) && $short_description ) {
?>
<p class="uo-course-short-desciption"><?php echo wp_kses_post( $short_description ); ?></p>
<?php
}
?>