Posted By

fjarrett on 11/09/10


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

joelhaus


Automatically Create Page When Theme Is Activated


 / Published in: PHP
 

URL: http://graphicriver.net/forums/thread/create-a-new-page-upon-theme-activation/33238?page=1

Simply replace 'Page Title' with your desired page title to automatically create the page when your theme is activated. Thanks to MattStrange for the original concept.

  1. // Automatically Create Page When Theme Is Activated
  2. $page_check = get_page_by_title('Sermon Media');
  3. $page_check_id = $page_check->ID;
  4. $new_page = array(
  5. 'post_type' => 'page',
  6. 'post_title' => 'Sermon Media',
  7. 'post_status' => 'publish',
  8. 'post_author' => 1,
  9. );
  10. if(!isset($page_check_id)){
  11. wp_insert_post($new_page);
  12. $new_page_data = get_page_by_title('Page Title');
  13. $new_page_id = $new_page_data->ID;
  14. update_post_meta($new_page_id, '_wp_page_template','page-template.php');
  15. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wpCanyon on November 9, 2010

Here is an improved version of this snippet. http://wpcanyon.com/tipsandtricks/automatically-create-a-page-on-theme-activation/

Posted By: wpCanyon on November 9, 2010

Sorry here is the clickable version http://wpcanyon.com/tipsandtricks/automatically-create-a-page-on-theme-activation/

You need to login to post a comment.