Filter Since 1.0.0 Dynamic uncanny-continuing-education-credits

{dynamic}_includes_path_to

> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the director path to the include file This can be used for template overrides by modifying the path to go to a directory in the theme or another plugin. Filters the include path to a template file, allowing for theme or plugin overrides.

add_filter( '{dynamic}_includes_path_to', $callback, 10, 2 );

Description

Filters the path to include template files. Developers can use this to override templates by redirecting the path to a theme or plugin directory. The hook name is dynamic, constructed at runtime based on the plugin or component.


Usage

add_filter( '{dynamic}_includes_path_to', 'your_function_name', 10, 2 );

Parameters

$templates_directory (string)
Path to the plugins template folder
$file_name (string)
The file name of the template file

Return Value

The filtered value.


Examples

// Example of how to override a plugin's template file path to include it from the theme.

add_filter( 'your_plugin_prefix_includes_path_to', 'my_theme_override_plugin_template_path', 10, 2 );

/**
 * Overrides the default plugin template path to point to a template in the theme.
 *
 * @param string $templates_directory The original path to the plugin's template directory.
 * @param string $file_name           The name of the template file being requested.
 *
 * @return string The modified path to the template file.
 */
function my_theme_override_plugin_template_path( $templates_directory, $file_name ) {

	// Construct the potential path for the template within the theme.
	// Assuming templates are stored in a 'templates/plugin-templates' sub-directory within the theme.
	$theme_template_path = trailingslashit( get_template_directory() ) . 'templates/plugin-templates/' . $file_name;

	// Check if the template file exists in the theme's specified directory.
	if ( file_exists( $theme_template_path ) ) {
		// If it exists, return the theme's path to be used.
		return trailingslashit( get_template_directory() ) . 'templates/plugin-templates/';
	}

	// If the template doesn't exist in the theme, return the original plugin path.
	return $templates_directory;
}

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/utilities.php:470

public static function get_include( $file_name ) {

		$includes_directory = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;

		/**
		 * Filters the director path to the include 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
		 */
		$includes_directory = apply_filters( self::get_prefix() . '_includes_path_to', $includes_directory, $file_name );

		$asset_path = $includes_directory . $file_name;

		return $asset_path;
	}


Scroll to Top