Create a new Page or Post Programmatically in WordPress

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

wordpress-beginner-guide

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 $new_page_id variable.

Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Solved Programs