uo_course_after_course_title
Fires after the course title is displayed, allowing for modifications or additions to the content.
add_action( 'uo_course_after_course_title', $callback, 10, 1 );
Description
Fires after the course title is displayed in the course grid template. Developers can use this hook to append custom content or modify the course title section. It's called after the `course-title` div and before other course information.
Usage
add_action( 'uo_course_after_course_title', 'your_function_name', 10, 1 );
Parameters
-
$course(mixed) - This parameter contains the course object, which holds all the information about the current course being displayed.
Examples
<?php
/**
* Example function to add content after the course title on course grid view.
* This function will display the course's short description if available.
*
* @param int $course_id The ID of the current course.
*/
function my_theme_display_course_short_description( $course_id ) {
// Get the course object.
$course_post = get_post( $course_id );
// Check if the course post exists and has a post content (which might be used for short description in some themes).
// In a real-world scenario, you might fetch a custom field for the short description.
if ( $course_post && ! empty( $course_post->post_content ) ) {
// Get the first part of the content as a short description (e.g., first sentence or paragraph).
// You might want to use a more sophisticated method to get a dedicated short description.
$short_description = wp_trim_words( $course_post->post_content, 20, '...' ); // Trim to 20 words.
// Output the short description wrapped in a specific HTML element.
echo '<div class="course-short-description">' . esc_html( $short_description ) . '</div>';
}
}
add_action( 'uo_course_after_course_title', 'my_theme_display_course_short_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:111
<div class="course-info-holder <?php echo esc_attr( $completed_class ); ?>">
<!-- Course title -->
<div
class="course-before-title"><?php do_action( 'uo_course_before_course_title', $course->ID ); ?></div>
<?php if ( 'no' === $atts['hide_title'] ) { ?>
<div class="course-title"><?php echo esc_attr( $course->post_title ); ?></div>
<?php } ?>
<div class="course-after-title"><?php do_action( 'uo_course_after_course_title', $course->ID ); ?></div>
<!-- Course title - End -->
<?php
/**
* Check plugin activity is not on the page plugins.
*/
require_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php';