Recently, I had to create a new page automatically in WordPress, when a Plugin was created.
I thought there will be a simple core function like
wp_insert_post which I can use. It turned out that create a new page from code is not that easy in WordPress. I ended up creating a new function myself wrapping the call to
I thought of posting it here so that I know where to look when I need it again 🙂
So here is the function.
It takes 5 parameters, out of which only one is mandatory.
$title– The title of the post (mandatory)
$content– The content of the post
$parent– The post id of the parent page. If this is the top level page, then pass 0
$page_template– The page template to use for this page
$menu_order– The menu order field.
While you are at it, you might also want to find out whether the page with that title already exists, before creating a new one.
- Email Log WordPress plugin v1.9.1 released
- Email Log WordPress plugin v1.9 released
- How to find if you are on the last page of a multi-page post in WordPress
- Easy Retweet WordPress plugin v3.1 Released
- Creating custom tables with correct Character Set and Collation in WordPress
- My contributions to WordPress 4.4