get_template_directory()
can be filtered. This can be useful when a plugin wants to interact with your theme, for example when you want to write custom plugins to extend the theme without changing it.
For example:
add_filter( 'template_directory', function( $template_dir, $template, $theme_root ) {
if ( some_condition( $theme_root ) ) {
return plugin_dir_path( __FILE__ ) . 'template';
}
});
include
is an expression, not a function, so omitting parentheses is fine.
Also note that plugin_dir_path()
has a trailing slash while get_template_directory()
doesn’t.