Using WordPress ‘get_default_page_to_edit()’ PHP function

The get_default_page_to_edit() WordPress PHP function retrieves the default page information to use.

Usage

$new_page = get_default_page_to_edit();

Parameters

  • None

More information

See WordPress Developer Resources: get_default_page_to_edit

Examples

Create a new page with default content

Create a new page with default content and save it as a draft.

$new_page = get_default_page_to_edit();
$new_page_id = wp_insert_post($new_page);

Set a new page title

Set the title of the new page created with default content.

$new_page = get_default_page_to_edit();
$new_page->post_title = 'My Custom Page Title';
$new_page_id = wp_insert_post($new_page);

Add content to a new page

Add custom content to the new page created with default content.

$new_page = get_default_page_to_edit();
$new_page->post_content = 'This is my custom page content.';
$new_page_id = wp_insert_post($new_page);

Set a new page template

Set a custom template for the new page created with default content.

$new_page = get_default_page_to_edit();
$new_page_id = wp_insert_post($new_page);
update_post_meta($new_page_id, '_wp_page_template', 'my-custom-template.php');

Publish a new page

Create a new page with default content and publish it immediately.

$new_page = get_default_page_to_edit();
$new_page->post_status = 'publish';
$new_page_id = wp_insert_post($new_page);

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *