Paulund
2014-05-12 #wordpress

Pre-populate Post Type Content

With custom post types you can separate the content into different section, for example you can post types, pages, portfolio pages and products. If you find that you enter the same content for different post types each time then you can use the WordPress filter default_content to set a template of default content you can use as the default content for your post types. Often people will ask for comments at the end of the post, such as: Let me know your thoughts in the comments. Instead of remembering to type this in each time you can setup the content editor to have this populated by default. Or if you have a portfolio post type you can add some text at the bottom of each post to contact you about further work. All you have to do is add the following code to your functions.php file.

add_filter( 'default_content', 'pu_default_editor_content' );

function pu_default_editor_content( $content ) {

    global $post_type;

    switch( $post_type ) 
    {
        case 'post':
            $content = 'Default content for blog posts.';
        break;

        case 'page':
            $content = 'Default content for pages.';
        break;

        case 'portfolio':
            $content = 'Default content for your portfolio pages.';
        break;

        case 'products':
            $content = 'Default content for blog posts.';
        break;
    }

    return $content;
}