Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. add_action( 'after_switch_theme', 'create_page_on_theme_activation' );
  2.  
  3. function create_page_on_theme_activation(){
  4.  
  5. // Set the title, template, etc
  6. $new_page_title = __('About Us','text-domain'); // Page's title
  7. $new_page_content = ''; // Content goes here
  8. $new_page_template = 'page-custom-page.php'; // The template to use for the page
  9. $page_check = get_page_by_title($new_page_title); // Check if the page already exists
  10. // Store the above data in an array
  11. $new_page = array(
  12. 'post_type' => 'page',
  13. 'post_title' => $new_page_title,
  14. 'post_content' => $new_page_content,
  15. 'post_status' => 'publish',
  16. 'post_author' => 1,
  17. 'post_slug' => 'about-us'
  18. );
  19. // If the page doesn't already exist, create it
  20. if(!isset($page_check->ID)){
  21. $new_page_id = wp_insert_post($new_page);
  22. if(!empty($new_page_template)){
  23. update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement