Prefilling new posts inside WordPress with a custom plugin

Create default content for new posts using a custom plugin. Add this to the code of your custom plugin:

1. Default post title

/* Add Default Title */
add_filter( 'default_title', 'my_editor_title' );
function my_editor_title( $title ) {
 $title = "Enter your title here";
 return $title;
}

2. Default post content

/* Add Default Content */
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {

 $content = "<h2>Enter the newsletter h2 title here</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas diam diam, aliquet quis egestas at, pharetra vitae metus. Morbi feugiat sem nec nulla ornare vel mattis dolor condimentum. Sed auctor viverra mattis. Pellentesque ac nibh nec eros euismod rhoncus at at ligula. Curabitur ut vestibulum massa. Integer mollis aliquam leo, vitae dictum arcu aliquet ut. Suspendisse tortor nunc, tempor non aliquet a, ultricies ac nisl. Nulla facilisi. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus in metus nulla.</p>";

return $content;
}

3. Default post featured image

/* Add default Featured Image */
function autoset_featured() {
 global $post;
 switch( $post->post_type ) {
 case 'eblast':

 $already_has_thumb = has_post_thumbnail($post->ID);
 if (!$already_has_thumb) {
 $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
 if ($attached_image) {
 foreach ($attached_image as $attachment_id => $attachment) {
 set_post_thumbnail($post->ID, $attachment_id);
 }
 } else {
 set_post_thumbnail($post->ID, '226');
 }
 }

 break; 
 }
} //end function
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');

After you add this to your custom plugin and activate your plugin, you will have preffiled content every time you click on ‘add new’ post.

Leave a Reply