Automatically Create Page When Theme Is Activated


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments


You need to login to view comments.