In this topic, We are going to see that How to create a page using the hook.
Here we use the wp_insert_post function to create a new page dynamically,
==> Add the below code in the function.php file of your child theme or your plugin file.
function add_new_page(){ $my_page = array( 'post_type' => 'page', 'post_title' => 'New page', 'post_content' => 'This is my New page.', 'post_status' => 'publish', ); wp_insert_post($my_page); } add_action('init','add_new_page');
Here, the init hook is used for the add page.
Please check the below image:
Thank You, hope you guys found something useful.