uo_single_group_template
Filters the template file used to display a single group on the front end.
add_filter( 'uo_single_group_template', $callback, 10, 1 );
Description
This filter hook, `uo_single_group_template`, allows developers to modify the template file used for displaying single group pages. It fires after the default template is determined but before it's loaded. Developers can use this hook to completely override the template, providing custom layouts or conditional logic for group displays. The `$single_template` parameter holds the path to the template file.
Usage
add_filter( 'uo_single_group_template', 'your_function_name', 10, 1 );
Parameters
-
$single_template(mixed) - This parameter contains the path to the template file that will be used to display a single group post.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the template used for displaying single LearnDash groups.
* This example checks if the current user has a specific role and, if so,
* overrides the default group template with a custom one.
*
* @param string $single_template The path to the current single group template file.
* @return string The path to the modified or original single group template file.
*/
function my_custom_group_template_filter( $single_template ) {
global $post;
// Ensure we are on a single group post type and the user has the 'group_leader' role.
if ( 'groups' === $post->post_type && current_user_can( 'group_leader' ) ) {
// Define the path to your custom single group template.
// This assumes your custom template is located in your theme's directory.
$custom_template_path = get_stylesheet_directory() . '/templates/single-group-leader.php';
// Check if the custom template file exists.
if ( file_exists( $custom_template_path ) ) {
// If it exists, return the path to the custom template.
return $custom_template_path;
}
}
// If the conditions are not met, or the custom template doesn't exist,
// return the original template path.
return $single_template;
}
add_filter( 'uo_single_group_template', 'my_custom_group_template_filter', 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/classes/learn-dash-group-sign-up.php:283
src/classes/learn-dash-group-sign-up.php:1122
public static function add_group_single_template( $single_template ) {
global $post;
if ( 'groups' === $post->post_type ) {
$single_template = self::get_template( 'single-group.php', dirname( dirname( __FILE__ ) ) . '/src' );
$single_template = apply_filters( 'uo_single_group_template', $single_template );
}
return $single_template;
}