How to create pages programmatically in wordpress

Creating the pages by using script or in wordpress is very easy. You just need to the following code snippet for create pages programmatically in wordpress. Many times we need to create the default page or post in wordpress. You just need to the following code snippet in functions.php file or your can put following code in your plugin file.

create pages programmatically in wordpress

If you are the wordpress plugin or theme developer then following code sample is rally useful to create the empty post or page in wordpress.

global $user_ID;
$page['post_type']    = 'page';
$page['post_content'] = 'Put your page content here';
$page['post_parent']  = 0;
$page['post_author']  = $user_ID;
$page['post_status']  = 'publish';
$page['post_title']   = 'Your Page Title';
$page = apply_filters('yourplugin_add_new_page', $page, 'teams');
$pageid = wp_insert_post ($page);

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.