daily pastebin goal
12%
SHARE
TWEET

dynamically create page/set static front page via functions

a guest Mar 28th, 2011 1,378 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if (isset($_GET['activated']) && is_admin()){
  4.         $new_page_title = 'Home';
  5.         $new_page_content = 'This is the page content';
  6.         $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
  7.         //don't change the code bellow, unless you know what you're doing
  8.         $page_check = get_page_by_title($new_page_title);
  9.         $new_page = array(
  10.                 'post_type' => 'page',
  11.                 'post_title' => $new_page_title,
  12.                 'post_content' => $new_page_content,
  13.                 'post_status' => 'publish',
  14.                 'post_author' => 1,
  15.         );
  16.         if(!isset($page_check->ID)){
  17.                 $new_page_id = wp_insert_post($new_page);
  18.                 if(!empty($new_page_template)){
  19.                         update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
  20.                 }
  21.         }
  22.        
  23.         $homeSet = get_page_by_title( 'Home' );
  24.         update_option( 'page_on_front', $homeSet->ID );
  25.         update_option( 'show_on_front', 'page' );
  26.  
  27. }
  28.  
  29. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top