Title: template redirect function for single php?
Last modified: August 20, 2016

---

# template redirect function for single php?

 *  Resolved [denl](https://wordpress.org/support/users/denl/)
 * (@denl)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/)
 * I have a custom post type in my child theme (of 2011). It’s added by a plugin.
   The single items are displayed in single-product.php and that works very well.
   But my problem is I need to display 3 different types of product and I want 3
   different single templates. I wondered if I could do something like check for
   a certain taxonomy like cats, dogs or mice and then send it to a different version
   of my single template, like single-product-dogs.php?
 * I found this on another site, can’t remember where now, I’ve been looking for
   ages…
 *     ```
       function my_template_redirect()
       {
       global $wp;
       if ($wp->query_vars["taxonomy"] == “example”)
       {
       include(TEMPLATEPATH . “/taxonomy-example.php”);
       die();
       }}
       add_action(“template_redirect”, ‘my_template_redirect’);
       ```
   
 * It looks like what I want to do but I’ve no idea where I should put it. Would
   this go in single-product.php or does it go in the functions file? And if it 
   would work how do I add the other two choices to the function?
 * I’d be gratefull for any ideas!

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

 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/#post-2711886)
 * [http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display](http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display)
 * Just follow the proper naming conventions for each term/tax, and your templates
   will be used automagically
 *  Thread Starter [denl](https://wordpress.org/support/users/denl/)
 * (@denl)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/#post-2711916)
 * Thanks for the idea. They don’t work though, it all goes to single-product.php
   instead. Although I’m probably misunderstanding how it should be named!
 * I’ve tried taxonomy-product-terms-dogs.php and that didn’t work but taxonomy-
   post_format-post-format-link.php is a bit confusing.
 * If My tax is called product-terms, my term is dogs and my custom post type is
   called productitems can you show me how I’d name that?
 * Sorry to be a bit slow!
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/#post-2711962)
 * I believe I misunderstood you. The naming conventions work great for getting 
   an archive/list of your custom tax posts, but not single view
 * Have a look through here:
    [http://wordpress.org/support/topic/single-post-template-for-custom-taxonomies?replies=4](http://wordpress.org/support/topic/single-post-template-for-custom-taxonomies?replies=4)
 * Basically you make an overall single.php, that doesn’t have the content display
   portion….
 * Use a conditional if/else to detect the terms, and bring in differing code based
   on the term, with logic like
 *     ```
       if -> cats
   
       get_template_part cats loop/display
   
       elseif -> dogs
   
       get_template_part dogs loop/display
   
       else
   
       get_template_part default single loop/display (or just includea/leave your standard single.php stuff here
   
       endif
       ```
   
 *  Thread Starter [denl](https://wordpress.org/support/users/denl/)
 * (@denl)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/#post-2711978)
 * Thanks! Yes that’s what I want to do. 🙂
 * thanks very much
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/#post-2711990)
 * Woo hoo! I’m glad that worked out for you!

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

The topic ‘template redirect function for single php?’ is closed to new replies.

## Tags

 * [single.php](https://wordpress.org/support/topic-tag/single-php/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 5 replies
 * 2 participants
 * Last reply from: [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/template-redirect-function-for-single-php/#post-2711990)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
