Title: Custom Posts / Custom Template Files
Last modified: August 20, 2016

---

# Custom Posts / Custom Template Files

 *  Resolved [Coldfight](https://wordpress.org/support/users/coldfight/)
 * (@coldfight)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-posts-custom-template-files/)
 * I created a plugin which creates a Custom Post Type. Every theme has their own
   single.php, and since I created my custom post type, I can have a single-custompost.
   php, in the Theme directory as well. this works.
 * The problem is I don’t want to put the single-custompost.php file in the Theme’s
   directory, I want to keep it isolated within my plugin directory. Is there some
   kind of hook, or another way that allows me to do this? I only want wordpress
   to look for single-custompost.php for my custompost, and not any other kind of
   post.
 * Thanks in advance.

Viewing 1 replies (of 1 total)

 *  Thread Starter [Coldfight](https://wordpress.org/support/users/coldfight/)
 * (@coldfight)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-posts-custom-template-files/#post-2816185)
 * I figured it out! For anyone who has the same problem, here is the fix:
 *     ```
       add_filter( "single_template", "get_custom_post_type_template" ) ;
   
       function get_custom_post_type_template($single_template) {
            global $post;
   
            if ($post->post_type == 'custom-post-type') {
                 $single_template = dirname( __FILE__ ) . '/single-custom-post-type.php';
            }
            return $single_template;
       }
       ```
   
 * I hope that helps other people!

Viewing 1 replies (of 1 total)

The topic ‘Custom Posts / Custom Template Files’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Coldfight](https://wordpress.org/support/users/coldfight/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/custom-posts-custom-template-files/#post-2816185)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
