Automatically Create A Page On Theme Activation


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



Copy this code and paste it in your HTML
  1. if ($_GET['activated']){
  2.  
  3. $new_page_title = 'This is the page title';
  4. $new_page_content = 'This is the page content';
  5. $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
  6.  
  7. //don't change the code bellow, unless you know what you're doing
  8.  
  9. $page_check = get_page_by_title($new_page_title);
  10. $new_page = array(
  11. 'post_type' => 'page',
  12. 'post_title' => $new_page_title,
  13. 'post_content' => $new_page_content,
  14. 'post_status' => 'publish',
  15. 'post_author' => 1,
  16. );
  17. if(!isset($page_check->ID)){
  18. $new_page_id = wp_insert_post($new_page);
  19. if(!empty($new_page_template)){
  20. update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
  21. }
  22. }
  23.  
  24. }

URL: http://wpcanyon.com/tipsandtricks/automatically-create-a-page-on-theme-activation/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.