The default_content WordPress PHP filter allows you to modify the default post content initially used in the “Write Post” form.
Usage
add_filter('default_content', 'your_custom_function', 10, 2); function your_custom_function($post_content, $post) { // your custom code here return $post_content; }
Parameters
$post_content
(string) – The default post content.$post
(WP_Post) – The post object.
More information
See WordPress Developer Resources: default_content
Examples
Add custom default content
This example sets custom default content for all new posts.
add_filter('default_content', 'set_custom_default_content', 10, 2); function set_custom_default_content($post_content, $post) { $post_content = "This is my custom default content!"; return $post_content; }
Set different default content based on post type
This example sets custom default content for different post types.
add_filter('default_content', 'set_default_content_by_post_type', 10, 2); function set_default_content_by_post_type($post_content, $post) { if ($post->post_type == 'post') { $post_content = "Default content for a blog post."; } elseif ($post->post_type == 'page') { $post_content = "Default content for a page."; } return $post_content; }
Add default content based on user role
This example sets custom default content for authors and editors.
add_filter('default_content', 'set_default_content_by_user_role', 10, 2); function set_default_content_by_user_role($post_content, $post) { $current_user = wp_get_current_user(); if (in_array('author', $current_user->roles)) { $post_content = "Default content for an author."; } elseif (in_array('editor', $current_user->roles)) { $post_content = "Default content for an editor."; } return $post_content; }
Set default content for a custom post type
This example sets custom default content for a custom post type called “product”.
add_filter('default_content', 'set_default_content_for_custom_post_type', 10, 2); function set_default_content_for_custom_post_type($post_content, $post) { if ($post->post_type == 'product') { $post_content = "Default content for a product."; } return $post_content; }
Append custom content to the default content
This example appends custom content to the default content for all new posts.
add_filter('default_content', 'append_custom_content', 10, 2); function append_custom_content($post_content, $post) { $custom_content = " This is my appended custom content!"; $post_content .= $custom_content; return $post_content; }