Using a boilerplate template when creating a new post in WordPress
While working on a new site, we decided to use a single template for publishing posts of a certain type.
Sounds a bit odd at first. The goal of securepulse.online is to notify subscribers about new software releases, patches and discovered vulnerabilities in various products. All news items of that kind have the type SecurityNews (the Toolset Types plugin handles the post typing).
After some back and forth we settled on the following sections for every news post:
- Description
- Changes
- Affected versions
- Recommended action
- Origin URLs
So the text editor needs to already have these sections when a post is created.
Achieved with the following code in wp-admin/edit-form-advanced.php.
Find this line:
<?php wp_editor( $post->post_content, 'content', array(
And add this before it:
<?php if ($post_type == '<strong>securitynews</strong>' && $action != '<code>edit</code>') {
$template = "<strong>Decription: </strong>\n\n";
$template .= "<strong>Changes: </strong>\n\n";
$template .= "<strong>Affected versions: </strong>\n\n";
$template .= "<strong>Recommended action: </strong>\n\n";
$template .= "<strong>Origin URLs: </strong>\n\n";
}
?>
And change the line itself to this:
<?php wp_editor( $post->post_content.''.$template, 'content', array()
Add the code in the Fires after the title field section, as shown in the screenshot:

The condition here is the post type securitynews plus the edit action.
Here’s what it looks like as a result:
