Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to offer my custom post type as a Plugin, so that people can use it without touching their theme folder. But custom post type templates -- such as single-movies.php -- reside in the theme folder. Is there a way to get WP to check for a single-movies.php in the plugin's folder? Hooking a function into the Filer Hierarchy? Or get_template_directory(); ?

share|improve this question

1 Answer 1

up vote 26 down vote accepted

you can use single_template filter hook

/* Filter the single_template with our custom function*/
add_filter('single_template', 'my_custom_template');

function my_custom_template($single) {
    global $wp_query, $post;

/* Checks for single template by post type */
if ($post->post_type == "POST TYPE NAME"){
    if(file_exists(PLUGIN_PATH. '/Custom_File.php'))
        return PLUGIN_PATH . '/Custom_File.php';
    return $single;
share|improve this answer
It's awesome answer. Please share were can I get all the template available hooks like single_template. –  Gowri May 2 '13 at 18:18
@gowri The filter is called by the get_query_template() function. It's a variable hook, so the first part {$type}_template changes depending on what parameter is passed to that function. See wp-includes/template.php for some common ones –  shea May 7 '13 at 9:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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