Creating a Custom Post Type for Inserting Preset Content into Post & Pages?

The question:

In response to Mike Schinkel‘s comment (see below) on my post about how to pre-populate content (essentially using a content template)…

@Scott B I mean why did you support a
file on disk rather than an place in
the admin? For multiple, have you
considering created a “Sales Letter”
custom post type?

No, but it sounds like a better solution. How would you do it and where would you store the choices for the content? (I assume you might have a few different types of content templates to offer.)

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Your question got me thinking about extending your use-case to a plugin I published earlier called WP Boilerplate Shortcode. I know your question isn’t about shortcodes but the name is only legacy for your use-case; indeed my extension I just added because of your question will do (almost) exactly what you are asking for (I’ll explain the “almost” part below).

I’m going to have to come back and document this more in-depth but I figured I’ve give you first access to it sooner than later (note the instructions.txt file does not address the new features yet):

The easy part of doing what you ask was the back-end coding; the harder part was figuring out a good UI. If there are multiple content items to choose from the user needs a way to select which one to use and there’s not one obvious way to do that.

One approach I could have used would have been to intercept when the user clicked “Add Post” and ask them which pre-populated content item they want to start with but that seemed kludgy and not in line with how the WordPress admin normally works. So instead I added a “Insert Boilerplate” metabox with a dropdown containing the list of available boilerplate text items.

To use this plugin download, copy to a subdirectory in your /wp-content/plugins/ directory and then activate it. After activation look for the “Boilerplate” menu and start adding your sales Letters as Boilerplates being careful to selecting the “Associated Post Types” for which you want each Boilerplate to be active. Then in the “Add {post type}” window in the admin look to the top right; you’ll find the content from the boilerplate to the end of whatever is currently in the content editor:

Creating a Custom Post Type for Inserting Preset Content into Post & Pages?

Note that upon activation the plugin will add any post types you might have into the “Associated Post Type” taxonomy but if you add new post types later you’ll have to add them manually; just make sure to match exactly the plural name of the post type (i.e. “Products” or “Featured Posts” or whatever.)

This isn’t exactly what you asked for but given the need for a way to select content I think it’s a really workable solution. I’d love to get your feedback on what you think of it.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment