Skip to content

Instantly share code, notes, and snippets.

@anik
Last active April 13, 2021 14:46
Show Gist options
  • Save anik/41893a05f824d3eadd1b47d7bac2cfad to your computer and use it in GitHub Desktop.
Save anik/41893a05f824d3eadd1b47d7bac2cfad to your computer and use it in GitHub Desktop.
<?php
$check_page_exist = get_page_by_title('title_of_the_page', 'OBJECT', 'page');
// Check if the page already exists
if(empty($check_page_exist)) {
$page_id = wp_insert_post(
array(
'comment_status' => 'close',
'ping_status' => 'close',
'post_author' => 1,
'post_title' => ucwords('title_of_the_page'),
'post_name' => strtolower(str_replace(' ', '-', trim('title_of_the_page'))),
'post_status' => 'publish',
'post_content' => 'Content of the page',
'post_type' => 'page',
'post_parent' => 'id_of_the_parent_page_if_it_available'
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment