Add default post content in WordPress content editor

Do you want the post editor to automatically insert a default content so that you can use it as a template or guidelines for writing posts or pages? If you want to have some default post content in the BODY content area for your new posts and pages, paste the following code in your theme’s functions.php file.

You can also check the $post_type of the ADD NEW page and include different default content based on the post type (pages or posts or custom posts) of the content being created. You can check for more POST TYPES using the SWITCH condition and adding new CASE for each post type.

<?php
add_filter( 'default_content', 'add_default_content' );
function add_default_content( $content ) {
	global $post_type;
	switch ( $post_type ) {
		case 'post':
			$content = "<p>This will be the first paragraph of all new BLOGPOSTS. I am adding a default paragraph. You can add any HTML code or text.</p>";
			break;
		case 'page':
			$content = "<p>This will be the first paragraph of all new PAGES. I am adding a default paragraph. You can add any HTML code or text.</p>";
			break;
	}
	return $content;
}
?>

One Reply to “Add default post content in WordPress content editor”

  1. If you want to automatically add specific default or pre-defined content to your editor while publishing posts or pages, then insert one of the following codes into functions.php:

    1)
    function add_before_content($content) {
    if ( ‘page’ == $post->post_type ) return $content .’Default page content.’;
    if ( ‘post’ == $post->post_type ) return $content .’Default post content.’;
    }
    add_filter(‘the_content’, add_before_content);

    2)

    function add_before_content($content) {
    return ‘Default Message’.$content;
    }
    add_action(‘publish_post’,add_before_content);
    add_action(‘update_post’,add_before_content);
    add_filter(‘the_content’, add_before_content);

Comments are closed.