Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to figure out a way to use a custom template within my plugin.

I would like to avoid using a custom post type if possible. I searched for a way to add my theme file to the dropdown list in the admin (under page attributes), but nothing seems to work.

Here is what I have:

add_filter('page_template', 'catch_plugin_template');

function catch_plugin_template( $template ) {
if( is_page_template('page_template.php') ){
    $template = WP_PLUGIN_DIR . '/myplugin/page_template.php';
    return $template;   
}
} 

However, since I can never select "page_template.php" from the template list it wont fire. Any suggestions on how to fix this or another way to approach it? I have considered changing the template based on whether or not certain post meta has a value, but I can't get that to work.

The code above works fine if I remove the if statement but I'm hoping for some sort of viable alternative.

share|improve this question
    
Please search the site (via Google) before asking. We've already had that question/answer. Example here, and another one is here –  kaiser Sep 15 '12 at 9:39
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.