Posted By

baires on 11/13/10


Tagged

template page wordpress


Versions (?)

Automatically Create A Page On Theme Activation


 / Published in: PHP
 

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

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wpCanyon on December 17, 2010

Hey, thanks for putting the link to the original post. The snipet was updated some time ago so if you want you can update it here too.

You need to login to post a comment.