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

Does exist some way to get the current searched hierarchy php page in Wordpress? I've set a default category to my posts named post so if I digit http://site.com/post which php page is searched in the hierarchy?

It would be great to get the current page searched.

share|improve this question
I'm sorry, but I just don't understand your question. Are you talking about static pages, or single blog post pages? If you're talking about static pages, then what does your default category have to do with the question? If you're talking about single blog post pages, what does hierarchy have to do with the question (perhaps the template hierarchy)? And in either case, what does search have to do with the question? – Chip Bennett Feb 10 '12 at 12:43
Poorly written, have no way to determine what you are trying to achieve. Please edit your question to clarify. – Brady Feb 10 '12 at 12:44
Well I try to reformulate the question, I know if I've created a Custom Post Type with the slug named photo Wordpress looking for the page single-photo.php, does exists some way to print which page it's looking for? – vitto Feb 10 '12 at 13:09
So, you want to know what template page is currently being displayed, within the template hierarchy? – Chip Bennett Feb 10 '12 at 13:15
up vote 1 down vote accepted

Assuming that you're wanting to determine which template page is currently being displayed, within the template hierarchy, the easiest way to do so is via the output of body_class().

However, if you need to return this information programmatically, the easiest way might be to call get_body_class(), and then evaluate the array of classes returned. Given the way that get_body_class() steps through each query conditional itself (and the template loader does likewise), I'm guessing that core doesn't have a more abstracted approach.

share|improve this answer
thank you, this is very useful! – vitto Feb 10 '12 at 13:44

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.