I am following the wp.tutsplus tutorial on Custom post types. Everything was fine until i added this code in my main plugin file

<?php add_filter( 'template_include', 'include_template_function', 1);?>

<?php function include_template_function(){
    if( get_post_type() == 'movie_reviews' ){
        if( is_single() ){
            if( $theme_file = locate_template( 'single-movie-reviews.php' ) ){
                $template_path = $theme_file;
                $template_path = plugin_dir_path( __FILE__ ).'single-movie-reviews.php';
    return $template_path;

I can still access the dashboard and create new posts but front page is blank. if i remove this code page loads without any problem.

  • What if you add $template_path to your function, like: function include_template_function( $template_path ) {? – Mike Madern Jul 15 '13 at 11:51
  • Oh man, i spent 2 pomodoros on this thing. Page is loading now. But it doesn't appear in the page template dropdown list. – Mohit Jul 15 '13 at 12:02
  • If movie-reviews is a CPT, single-movie-reviews.php should be loaded auto-magically. Why are you doing this manually and why do you need it to show up in the template dropdown? – s_ha_dum Jul 15 '13 at 13:32
  • I am following this tutorial wp.tutsplus.com/tutorials/plugins/… – Mohit Jul 15 '13 at 13:36
  • @s_ha_dum I want to add a page called Movie Reviews which will show all the reviews and for that i need to use the Movie reviews template. – Mohit Jul 15 '13 at 14:33

To solve your issue with the page template not showing up in the template dropdown list

In your single-movie-reviews.php, add the following at the top of the file:

Template Name: My Custom Page

Where you change My Custom Page into the template name of your choice.

See This Codex page for more information about Custom Page Templates.

| improve this answer | |

WordPress will load a file named single-movie-reviews.php automatically for single Movie Review (CPT named movie-reviews) posts, or will load archive-movie-reviews.php for the archive listing. See the Template Hierarchy Codex page.

That template_include filter appears to me to be doing (or attempting to do) exactly what the Core does automatically. I have no idea what its purpose it. Just leave that part out and name your files appropriately so that the WordPress Core can do its job.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.