Add Default Content to New Posts

With WordPress hooks you can easily add default content to new posts, if you are repeatedly entering some content into all your posts this is a great productivity aid. Just insert the following into your functions.php file, editing the value of the $content variable to reflect the message you want to insert into new posts.

You can also use conditionals to apply this to specific post types:

If you enjoyed this post, make sure to subscribe to my rss feed.

About Jean Galea

Jean Galea is a WordPress developer, entrepreneur and padel player. He is the founder of WP Mayor, the plugins WP RSS Aggregator and EDD Bookings, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Related Articles

5 Responses

  1. Jon
    Jon December 11, 2012 at 17:32 | | Reply

    Thanks for this, though is it possible to add line breaks in the content? I wanted to add a number of headings but they all appear as one long string rather than below each other.

  2. sleno
    sleno January 24, 2013 at 11:30 | | Reply

    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);

  3. Amri
    Amri February 9, 2017 at 12:25 | | Reply

    can add a title, category OR tag with this?

Leave a Reply