Home  »  CodeSnippets   »   Create new Page Programmatically in WordPress

Create new Page Programmatically in WordPress

Posted: May 11, 2022 | by Site Host

Use this code snippet to programmatically create new page in WordPress:

$new_page = array(
    '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_author' => $user_ID,
    'post_type' => 'page',
    'comment_status' => 'close',
    'ping_status' => 'close',
    'post_parent' => 'id_of_parent_page_if_available'
);
$post_id = wp_insert_post( $new_page );

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Share it!

See also  Moment.js CDN Cheatsheet