If you want to create some demo pages OR Posts during your custom wordpress theme installation, then you can use the
wp_insert_post() function inside your functions.php file.
Open functions.php file of your theme’s folder and copy paste below code at the end of the file. Below code will create a new page when code will execute. And of course It will be work for POST and other custom post type. You need to change
'post_type' => 'post'.
wp_insert_post function will returns the ID of the newly-created page or post in
$new_page_id variable. If it will occure an error, it will return 0 in
//define your page content in below array
$new_page = array(
'slug' => 'this-is-my-new-page',
'title' => 'Write a Headline that Captivates',
'content' => "Enter the body Content for your Page here"
$new_page_id = wp_insert_post( array(
'post_title' => $new_page['title'],
'post_type' => 'page',
'post_name' => $new_page['slug'],
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_content' => $new_page['content'],
'post_status' => 'publish',
'post_author' => 1,
'menu_order' => 0
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari
Tags: how to create a new page and post in wordpress, how to create a new page in wordpress, wordpress, wordpress beginner, wordpress beginners, wordpress beginners tutorial, wordpress tips and tricks, wordpress tutorials for beginners