Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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 */
print_r($template);

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

share|improve this answer
add comment

Your Answer

 
discard

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.