Create a new Page

If you want your Theme or Plugin to create a new page (or two or three) on its own, here is some quick code to do it. Just put this into an activation hook, and you’ll be good to go.

wp_insert_post returns the ID of the newly-created page. In the event of an error, it will return 0 if $wp_error is set to false, or a WP_Error object if $wp_error is set to true.

And of course, this code could be used to create a POST or any other type of Custom Post Type content, just by changing the value for “post_type”.

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!