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've created a child theme basing on twenty twelve.

Since I present the content a little bit different on home and on the archive page, I'd like to know inside content-[format].php on which page the post is being rendered. Then, I can decide which image size I can present.

How can I know it?

share|improve this question
up vote 1 down vote accepted

You can use the global $template. The following function returns the basename of the template file being used: index, archive, etc.

function get_template_name_wpse_85011()
    global $template;
    $filename = basename( $template, '.php' );
    return $filename;

And use it in your template with something like:

$templat = get_template_name_wpse_85011();
switch( $templat )
    case 'index':
        // do index
    case 'archive':
        // do archive
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.