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.

2 Answers 2


Issue was with UT_TEMPLATES_URLused for including the template.

I was using file URL and not file PATH which was creating the issue.

Modifying the UT_TEMPLATES_URL, to FILE 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:

global $wp_query;

This should work.


Jørgen Juel

  • That function is working quiet ok, problem is with template inclusion. I'm getting proper values for get_query_var('taxonomy')
    – Kumar
    Dec 29, 2013 at 11:38
  • get_query_var() itslef uses $wp_query, I need not use $wp_query in my function.
    – Kumar
    Dec 29, 2013 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.