Filter uncanny-learndash-toolkit

uncanny_toolkit_template_path

Filters the template path for Uncanny Toolkit core templates, allowing customization of file locations before they are loaded.

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

Description

Filters the default template path for Uncanny Toolkit assets. Developers can use this to specify custom template directories or modify the base path where Uncanny Toolkit looks for its template files.


Usage

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

Parameters

$file_name (mixed)
This parameter provides the base path for Uncanny Toolkit templates, including the plugin directory and a directory separator.

Return Value

The filtered value.


Examples

/**
 * Example of modifying the template path for Uncanny Toolkit templates.
 *
 * This filter allows you to change the base directory where Uncanny Toolkit
 * looks for its template files. For instance, you might want to load
 * custom templates from a child theme's directory.
 */
add_filter( 'uncanny_toolkit_template_path', function( $template_path, $file_name ) {
	// Check if we're dealing with a specific file that requires a custom path.
	// For this example, let's say we want to load a 'custom-dashboard.php'
	// from a 'my-custom-templates' directory within the main plugin directory.
	if ( 'custom-dashboard.php' === $file_name ) {
		// Construct the new path. Replace 'your-plugin-folder' with the actual
		// folder name of the plugin that contains this code.
		// Using plugin_dir_path() is generally the most reliable way to get
		// the absolute path to a plugin's directory.
		$new_path = plugin_dir_path( __FILE__ ) . 'my-custom-templates/';
		return $new_path;
	}

	// If it's not the specific file we want to modify, return the original path.
	return $template_path;
}, 10, 2 );

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/config.php:107

public static function get_template( $file_name, $file = false ) {

		if ( ! $file ) {
			$file = __FILE__;
		}
		$template_path = apply_filters( 'uncanny_toolkit_template_path', 'uncanny-toolkit' . DIRECTORY_SEPARATOR, $file_name );
		$asset_uri     = self::locate_template( $template_path . $file_name );

		if ( empty( $asset_uri ) ) {
			$asset_uri = dirname( $file ) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $file_name;
		}

		return $asset_uri;
	}

Scroll to Top