---
url: /hooks/filters/wpce-default-document.md
description: Filter the default document tree used when a new post is created.
---

# `wpce_default_document`&#x20;

Filters the default document in the editor.

This allows to set a custom root node for a new post's document.

## Parameters

1. `?object $root_node`

   The document's root node. `null` if no default document is set.

2. `WP_Post $post`

   The post the document is created for.

3. `WPCE $wpce`

   The WPCE instance.

## Example

```php
add_filter('wpce_default_document', function (?object $root_node, WP_Post $post, WPCE $wpce) {
	// Set a custom root node for the 'my_custom_post_type' post type
	if ($post->post_type === 'my_custom_post_type') {
		$root_node = (object) [
			'id' => 'root',
			'label' => 'My Custom Post Type',
			'properties' => [],
			'children' => [
				(object) [
					'id' => 'text',
					'name' => 'Text',
					'children' => [],
					'properties' => [
						'content' => '<p>Lorem ipsum dolor sit amet...</p>',
					],
					'visible' => true,
				],
			],
			'visible' => true,
		];
	}

	return $root_node;
}, 10, 3);
```
