uo_course_grid_before_action_buttons
Fires before course action buttons are displayed on the course grid.
add_action( 'uo_course_grid_before_action_buttons', $callback, 10, 1 );
Description
Fires before the action buttons (like "Start Course" or "Resume Course") are displayed in the Uncanny Pro Toolkit course grid. This hook allows developers to add custom content or modify the layout before the default action buttons.
Usage
add_action( 'uo_course_grid_before_action_buttons', 'your_function_name', 10, 1 );
Parameters
-
$course(mixed) - This parameter contains the current course object being displayed in the grid.
Examples
<?php
/**
* Add a custom class to the course action button wrapper if the course is in a specific category.
*
* @param mixed $course The course object being rendered.
*/
add_action(
'uo_course_grid_before_action_buttons',
function ( $course ) {
// Check if the course object is valid and has a way to get its terms.
if ( is_object( $course ) && method_exists( $course, 'get_terms' ) ) {
$terms = $course->get_terms( 'category' ); // Assuming 'category' is the taxonomy to check.
if ( ! empty( $terms ) && is_array( $terms ) ) {
foreach ( $terms as $term ) {
// Replace 'your-custom-category-slug' with the actual category slug you want to target.
if ( $term->slug === 'your-custom-category-slug' ) {
// Add a custom class to the surrounding div for styling.
// Note: This example assumes the hook is placed *before* the action button div.
// If you need to modify the div itself, you might need to access the parent element
// or potentially use a filter if available for modifying HTML.
// For demonstration, we'll assume we can influence a parent or the immediate context.
// A more realistic approach might involve echoing inline styles or a JavaScript hook.
// For this example, we'll assume a simple class addition is desired for demonstration.
echo '<div class="uo-toolkit-grid__course-action custom-category-highlight">';
break; // Exit loop once a matching category is found.
}
}
}
}
},
10, // Priority
1 // Accepted 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:214
<?php
/* translators: LearnDash course title */
if ( sprintf( esc_html__( 'View %s Outline', 'uncanny-pro-toolkit' ), LearnDash_Custom_Label::get_label( 'course' ) ) !== $status_icon && 'Coming Soon' !== $status_icon ) {
if ( ( 'show' === $show_start_button && 0 === $percentage ) || ( 'show' === $show_resume_button && $percentage > 0 && $percentage < 100 ) ) {
?>
<div class="uo-toolkit-grid__course-action">
<?php do_action_deprecated( 'uo-course-grid-before-action-buttons', array( $course ), '3.7.11', 'uo_course_grid_before_action_buttons' ); ?>
<?php do_action( 'uo_course_grid_before_action_buttons', $course ); ?>
<?php
if ( 'show' === $show_start_button && 0 === $percentage ) {
/* translators: LearnDash course title */
$btn_text = sprintf( esc_html__( 'Start %s', 'uncanny-pro-toolkit' ), class_exists( 'LearnDash_Custom_Label' ) ? LearnDash_Custom_Label::get_label( 'course' ) : 'course' );
$start_button_html = sprintf( '<a href="%s"><input type="submit" value="%s" class="" /></a>', $permalink, $btn_text );
$start_button_html = apply_filters_deprecated(
'uo-course-grid-start-button',