• Resolved Coldfight

    (@coldfight)


    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

    (@coldfight)

    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.