uncanny_codes_template_path
Filters the template path for Uncanny Codes, allowing customization of where templates are loaded from.
add_filter( 'uncanny_codes_template_path', $callback, 10, 1 );
Description
Filters the default template path for Uncanny Codes. Developers can use this to point to custom template locations, allowing for theme overrides or advanced customization of Uncanny Codes' presentation. The default path is 'uncanny-codes/'.
Usage
add_filter( 'uncanny_codes_template_path', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to modify the template path for Uncanny Codes.
*
* This filter allows you to change the default directory where Uncanny Codes
* looks for its template files. For instance, you might want to organize
* your custom templates within a theme's structure.
*
* @param string $template_path The default template path provided by Uncanny Codes.
* @return string The modified template path.
*/
add_filter( 'uncanny_codes_template_path', 'my_custom_uncanny_codes_template_path', 10, 1 );
function my_custom_uncanny_codes_template_path( $template_path ) {
// Example: If using a child theme, you might want to place custom templates
// within your child theme's directory.
// This example prepends a 'my-custom-templates' directory to the path.
// Replace 'my-custom-templates' with your actual directory name.
// Ensure we are within a WordPress environment to use get_stylesheet_directory_uri() safely
if ( function_exists( 'get_stylesheet_directory_uri' ) ) {
// You could potentially combine this with the original path if needed
// return 'my-custom-templates' . DIRECTORY_SEPARATOR . $template_path;
// Or, completely override the path to point to a theme directory structure
// This would require Uncanny Codes to also use locate_template() correctly
// with a full path, which it seems to do internally.
// For simplicity, this example adds a subdirectory within the default.
return 'my-custom-templates' . DIRECTORY_SEPARATOR . $template_path;
}
// Fallback to original if not in a WordPress environment or if get_stylesheet_directory_uri is not available
return $template_path;
}
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:316
public static function get_template( $file_name, $file = false ) {
$template_path = apply_filters( 'uncanny_codes_template_path', 'uncanny-codes' . DIRECTORY_SEPARATOR );
$asset_uri = self::locate_template( $template_path . $file_name );
if ( empty( $asset_uri ) ) {
if ( false === $file ) {
$file = __FILE__;
}
$asset_uri = dirname( $file ) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $file_name;
}
return $asset_uri;
}