Title: Conditional template tag
Last modified: August 18, 2016

---

# Conditional template tag

 *  [andyhume](https://wordpress.org/support/users/andyhume/)
 * (@andyhume)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-template-tag/)
 * HI guys,
 * Is there a built in WordPress function that returns the name of the page template
   that is being displayed? Much like, is_page(‘pagename’), but more like, is_template(‘
   template’) – I tried this but it didn’t work!
 * If no such thing exists, is there some variable exposed that will let me test
   what template is being viewed?
 * Thanks very much
 * Andy.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-template-tag/#post-313109)
 * Do you mean [Page](http://codex.wordpress.org/Pages) template? or just any template?
   
   Actually I don’t know the answer – all the [Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)
   are at this link. If it’s about Page templates – Pages use the template you select
   or… according to [Template_Hierarchy](http://codex.wordpress.org/Template_Hierarchy).
 *  Thread Starter [andyhume](https://wordpress.org/support/users/andyhume/)
 * (@andyhume)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-template-tag/#post-313122)
 * Yeah, I mean page template. So I can do different things in say, header.php, 
   depending on what template is being used.
 * I’ve actually found a way of doing this aftyer digging through functions.php 
   for a bit. get_page_template() returns the name of the template but with the 
   entire absolute address of the server as well. So it’s a bit long winded, but
   is doing the job! 🙂
 * There really should be a nice clean function to find what page template you are
   using though. As I suggest earlier:
 * is_template(‘name’) would be good.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-template-tag/#post-313142)
 * “_There really should be a nice clean function to find what page template you
   are using though._“
 * Any Page assigned a template retains it in the ‘_wp_page_template’ custom field.
   Here’s your function:
 * [http://paste.uni.cc/8446](http://paste.uni.cc/8446)
 * Note I call the function is_page_template() to clarify use (and avoid conflict
   with any is_template() function appearing later). If running WordPress 2.0, you
   can drop this in a functions.php file and save it with your active theme, and
   WordPress will automatically include it.
 *  Thread Starter [andyhume](https://wordpress.org/support/users/andyhume/)
 * (@andyhume)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-template-tag/#post-313200)
 * Nice one Kafkaesqui. That’s exactly what I was looking for. Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Conditional template tag’ is closed to new replies.

## Tags

 * [logic](https://wordpress.org/support/topic-tag/logic/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [andyhume](https://wordpress.org/support/users/andyhume/)
 * Last activity: [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-template-tag/#post-313200)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
