6

Basically I've made a plugin to create a new post type (event).

Now I want to create a single-event.php layout file.

I don't want to have to stick it in the theme folder, I want to put it into my plugin folder. How do I make wordpress know its there?

Thanks

  • well dice the template system looks in the themes folder I think that this is the only way unless there is a filter. usually you put the register post type in the functions.pho – xLRDxREVENGEx May 18 '11 at 17:05
6

Here is the code that will let you return your single-event.php if the post type is event:

function my_event_template($single_template) {
    global $post;

    if ($post->post_type == 'event') {
        return dirname( __FILE__ ) . '/single-event.php';
    return $single_template;
}

add_filter( "single_template", "my_event_template" ) ;
| improve this answer | |
  • I learned something today. Yay. thanks hameedullah i was not sure if there was a filter or not for this. – xLRDxREVENGEx May 18 '11 at 17:51
  • 1
    Glad that I was able to help you learn something new. :) – Hameedullah Khan May 18 '11 at 18:09

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.