Interesting Idea: Theme that Creates Pages, Automatically

Alex raised a good question at the wp-hackers mailing list:

I am interested in the opinion of people on this list as to whether they see any problem in a theme adding Pages to the database when it is activated…

This, it turns out, is perfectly possible, as explained by Alan J. Castonguay:

A theme is just a visually-oriented plugin, and can do anything that a ‘normal’ plugin can do, including wp_insert_post()’ing Pages. The theme’s functions.php file is loaded in wp-settings.php, just after the plugins, but before the init hook, for every page load.

How awesome. Can you imagine it now? Create a theme that automatically install a Contact Form for the users! Or pretty much any other pages that gets filled by plugins, only in this case the page is automatically there instead of requiring users to create that page and input whatever the magic keyword needed to invoke a plugin’s functionality. Woah.

(Of course, it’s probably best to ask user first whether they want to create that Page, but still.)

You may also like...

2 Responses

  1. Rick Beckman says:

    If I’m not mistaken, the theme K2 could do this; it had an admin option of whether or not to create an archives page.

    My personal opinion is I’d rather be in control of my own pages. A person may already have all sorts of pages, and if activating themes becomes an exercise in deleting duplicated or conflicting pages then the “create page” feature could quickly become an annoyance.

    Could be useful for people just getting started out, though.

  2. Hafiz Rahman says:

    I agree wholeheartedly, which is why I mentioned that it’s best to ask the user first. Or, in other words, not automating the page creation during theme activation, but give some sort of admin option to do so.

css.php