WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a plugin that lets people add course information online. 'Courses' is a custom post type. I've already made the admin menu to add the course information to the database (in the post meta table).

Now I need to bring it out onto the front end. Ideally I'd like to make a new template page (single-courses.php) so I can fully customise the page. I've not found anything that fits the bill online yet, is there an easy way of generating this through the plugin?


share|improve this question

I managed to do it, not perfect but it works...

add_action('template_redirect', 'my_template');

function my_template(){
global $post;
if( get_post_type($post->ID) == 'courses'){
include(ABSPATH. 'wp-content/plugins/courses/single-course.php');

And the file the include points to is my new template file in the plugin.

share|improve this answer
Use plugin_dir_path(). wp-content can be moved and renamed. – toscho Jun 25 '12 at 13:53
With the uncertainty of themes, I think this is generally a challenge. You might look at The Events Calendar which has fairly robust templating for a plugin. They do something similar to this. Also, you might consider filtering the_content instead of adding a template. That strikes me as much safer when it comes to cross-theme compatibility. – mrwweb Jun 25 '12 at 17:47
Yep I actually did a filter on the_content first, i agree i thought it was safer, but my boss and collegues seemed to think a template would be better so just doing what I'm told! Thanks for the answers, I've kept it as it is redirecting to the new template, I checked out the event calendar, there is some good but quite heavy stuff there! And I'll change the abspath to something more futureproof. Thanks :) – danbrown Jul 2 '12 at 7:55

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.