WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made a custom taxonomy called - work-category and a template file for it called - taxonomy-work-category.php. That part work just fine.

For a purpose I did put get_page_template() in that taxonomy-work-category.php file to get the current template file name. But it does print out as page.php (with full path ofcourse). I was expecting it to print out taxonomy-work-category.php.

Even when I'm certain it is printing out from a custom taxonomy template file - Why doesn't get_page_template() function doesn't returns the taxonomy template file name?

share|improve this question
up vote 0 down vote accepted

get_page_template returns the template of the current active post/page. You're not on a post/page though, you're in a listing/archive.

When you get page.php what you're seeing is the template of the first post/page. The taxonomy listing itself is not a page, it's a listing, and so it makes no sense for it to have a page template, as it is not a page.

See here for an answer that should do what you want:

get name of the current template file

this may also work:

/* show me what the body class will look like */
echo body_class() . "\n";

/* make sure i've got $template */
global $template;

/* print the active template path and filename */

( Although why check if you're in template X inside template X, surely the answer will always be yes? )

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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