Title: Adding page template via plugin
Last modified: August 20, 2016

---

# Adding page template via plugin

 *  [David](https://wordpress.org/support/users/dlabbe/)
 * (@dlabbe)
 * [15 years ago](https://wordpress.org/support/topic/adding-page-template-via-plugin/)
 * I just built a plugin for someone that allows them to insert a simple weekly 
   schedule of classes they are running for school. With the plugin I had to create
   2 custom page templates in my child-themes folder that holds the display code
   for the schedule itself and another page to display details about the class. 
   I am trying to wrap my head around how to include the page creation on plugin
   activation instead of having to manually create the pages and insert them into
   my theme.
    I am playing with wp_insert_post but am having no luck. Any help would
   be greatly appreciated…thanks. Please let me know if this makes sense and if 
   not I will try to explain the issue in better detail.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [David](https://wordpress.org/support/users/dlabbe/)
 * (@dlabbe)
 * [15 years ago](https://wordpress.org/support/topic/adding-page-template-via-plugin/#post-2098309)
 * here is a link i found that shows a snippet that I tried with no luck. However
   it seems to be close to what I need…any ideas?
 * [http://wpsnipp.com/index.php/functions-php/create-page-on-theme-activation/](http://wpsnipp.com/index.php/functions-php/create-page-on-theme-activation/)
 *  Thread Starter [David](https://wordpress.org/support/users/dlabbe/)
 * (@dlabbe)
 * [15 years ago](https://wordpress.org/support/topic/adding-page-template-via-plugin/#post-2098515)
 * any one?
 *  [kiko0850](https://wordpress.org/support/users/kiko0850/)
 * (@kiko0850)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/adding-page-template-via-plugin/#post-2098751)
 * It might be late but, wp_insert_post works for me the only part that I wasn’t
   able to get to work is assigning the template file as well using update_metadata.
 * I found a work around online though [http://wordpress.stackexchange.com/questions/3396/create-custom-page-templates-with-plugins](http://wordpress.stackexchange.com/questions/3396/create-custom-page-templates-with-plugins),
   it’s based on when a page is served up if it has the condition specified then
   it will return your own custom template instead of it’s original template. Obviously
   this will not show the template’s filename when you edit the page/post and you
   won’t be able to change that page’s template file. So this will be a good idea
   if you don’t want users to ever change the way it looks, but it could also frustrate
   the user as to why their assigned template isn’t working.
 * Also another way is where when you activate your plugin to just copy your template
   files from your template folder within your plugins folder over to the currently
   activated theme if that file doesn’t exist and also update the metadata to the
   filename. In theory that should work as well (looked at them Shopp plugin and
   that’s the way they implemented adding their templates to the current theme)
 * UPDATE: I did implement it the Shopp way and it works like a charm
    🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding page template via plugin’ is closed to new replies.

## Tags

 * [display](https://wordpress.org/support/topic-tag/display/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [pages](https://wordpress.org/support/topic-tag/pages/)

 * 3 replies
 * 2 participants
 * Last reply from: [kiko0850](https://wordpress.org/support/users/kiko0850/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/adding-page-template-via-plugin/#post-2098751)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
