Block Editor PHP Beginner

Start New Posts With Default Content

Pre-fill new posts with blocks or text, such as an introduction prompt and a call-to-action, so every post starts with your structure.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 17 lines
add_filter( 'default_content', function ( string $content, WP_Post $post ): string {
	if ( 'post' !== $post->post_type ) {
		return $content;
	}

	return '<!-- wp:paragraph {"placeholder":"Start with a one-sentence summary…"} -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Key takeaways</h2>
<!-- /wp:heading -->

<!-- wp:list -->
<ul class="wp-block-list"><!-- wp:list-item --><li></li><!-- /wp:list-item --></ul>
<!-- /wp:list -->';
}, 10, 2 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

If your posts follow a structure, like a summary, then takeaways, then the body, starting each one from a blank page means retyping it every time. This snippet pre-fills new posts with that structure.

How it works

WordPress passes the content of every new post through default_content before opening the editor. Returning block markup gives writers real blocks to fill in, here a summary paragraph with a placeholder, a “Key takeaways” heading and an empty list.

Only new posts are affected. Existing posts are never changed.

Things to watch

  • The easiest way to get the markup is to build the layout in the editor, then copy it from the Code editor.
  • For a structure editors can’t change, use a post type template with locking instead.

How to test it

Click Posts → Add New. The editor should open with your blocks already in place.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only