Support » Plugins » 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)
  • 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?

    any one?

    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, 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.