Filter uncanny-learndash-groups

uncanny_groups_template_path

Filters the path where Uncanny Groups templates are loaded, allowing customization of template file locations.

add_filter( 'uncanny_groups_template_path', $callback, 10, 1 );

Description

Filters the base directory path for Uncanny Groups template files. Developers can use this hook to relocate or override template files by returning a custom path. Ensure the returned path is a string ending with a directory separator.


Usage

add_filter( 'uncanny_groups_template_path', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Override the default Uncanny Groups template path to point to a theme override directory.
 *
 * This allows developers to customize the look and feel of Uncanny Groups templates
 * without modifying the plugin's core files.
 *
 * @param string $template_path The default template path.
 * @return string The modified template path.
 */
add_filter( 'uncanny_groups_template_path', function( $template_path ) {
    // Construct the potential override path within the current theme.
    $theme_override_path = trailingslashit( get_stylesheet_directory() ) . 'uncanny-groups-templates/';

    // Check if the override directory exists.
    if ( file_exists( $theme_override_path ) ) {
        // If it exists, prepend it to the default path. The plugin's locate_template
        // function will then search this path first.
        return trailingslashit( $theme_override_path ) . $template_path;
    }

    // If no override directory is found, return the original path.
    return $template_path;
}, 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/class-utilities.php:472

public static function get_template( $file_name ) {

		$template_path = apply_filters( 'uncanny_groups_template_path', 'uncanny-groups' . DIRECTORY_SEPARATOR );
		$asset_path    = self::locate_template( $template_path . $file_name );

		if ( empty( $asset_path ) ) {
			$templates_directory = ULGM_ABSPATH . 'src/templates' . DIRECTORY_SEPARATOR;

			/**
			 * Filters the director path to the template file
			 *
			 * This can be used for template overrides by modifying the path to go to a directory in the theme or another plugin.
			 *
			 * @param string $templates_directory Path to the plugins template folder
			 * @param string $file_name The file name of the template file
			 *
			 * @since 1.0.0
			 */
			$templates_directory = apply_filters( 'ulgm_template_path', $templates_directory, $file_name );

			$asset_path = $templates_directory . $file_name;
		}

		return $asset_path;
	}


Scroll to Top