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 am trying to make a personal plugin that does specific things based on what is loaded. In this example, in my action method I want to perform one function if the currently loading page is using the template-blog.php template, if it's a single blog post (loading single.php do a second function, anything else do a 3rd function

I am not quite sure what method I need to use, and so far Google is not pulling up the right methods. I have been trying get_current_template(), get_template() get_page_template(), but none of them pull the stuff I am looking for above.

share|improve this question
google template_include then – Jesse Apr 30 '13 at 2:28
This answer seems to be exactly what you're looking for, does it not? – montrealist Apr 30 '13 at 2:57
In addition to dalbeab's answer, I just want to say that if you want to style the blog page (i.e. the page on which all the posts get output), then you should use home.php instead of a custom page template. – Fränk Apr 30 '13 at 10:18
up vote 0 down vote accepted

Using body_class() on the body tag would probably be the easiest way to tell which template is in use.

<body <?php body_class(); ?>>

Depending on which page you are on, it will output similar to this

<body class="page page-id-10 page-template-default logged-in">

Where page-template-default is the template in use. It's also useful for blog posts and custom post types.

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.