I’m using taxonomy_template filter in my plugin to load a template file for custom user taxonomies. This is the code I’m using
add_filter( 'taxonomy_template', 'get_custom_taxonomy_template' );
function get_custom_taxonomy_template($template) {
$taxonomy = get_query_var('taxonomy');
if (strpos($taxonomy,'rcm_user_') !== false) {
$taxonomy_template = UT_TEMPLATES_URL ."user-taxonomy-template.php";
$file_headers = @get_headers($taxonomy_template);
if( $file_headers[0] != 'HTTP/1.0 404 Not Found'){
return $taxonomy_template;
}
}
return $template;
}
It loads the file but I get fatal error for wordpress functions like
get_header(), _e()
I’ve tried using default theme, saving permalink structures.
Issue was with
UT_TEMPLATES_URL
used for including the template.I was using
file URL
and notfile PATH
which was creating the issue.Modifying the
UT_TEMPLATES_URL
, toFILE PATH
fixes the issue.The get_query_var function requires the wp_query object, and it is not within your functions scope – so you need to include it:
This should work.
—
Jørgen Juel