Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Add Default Content in Your WordPress Post Editor

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Add Default Content in Your WordPress Post Editor

Have you ever find yourself entering the same text in all of your posts? Often people do that such as asking people to subscribe to their feeds, retweet the post, share it on facebook etc. You can always use a simple tag to add it right after the content, or you can add that text as the default content in your WordPress post editor.

Simply open up your WordPress theme’s functions.php file and paste the following code within the PHP tags ofcourse.

add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
	$content = "If you like this post, then please consider retweeting it or sharing it on Facebook.";
	return $content;
}

And you are done. Try to create a New Post, and you should see the new content there.

Update (January 24, 2013) – One of our users asked us how to add different content for different post type in the comments. The code below will show you how to add different default content in your WordPress post editor for each specific custom post type:

add_filter( 'default_content', 'my_editor_content', 10, 2 );

function my_editor_content( $content, $post ) {

    switch( $post->post_type ) {
        case 'sources':
            $content = 'your content';
        break;
        case 'stories':
            $content = 'your content';
        break;
        case 'pictures':
            $content = 'your content';
        break;
        default:
            $content = 'your default content';
        break;
    }

    return $content;
}

Source: Justin Tadlock


Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Grant Skinner says:

    I’ve used the code you gave in the first instance and it works great, thanks.
    Q – How do I add hyper links on certain works like if I have a “Click Here” portion of text that links the user to a new page.
    Any hel would be appreciated.

  2. Krishna says:

    Would you please help me by telling how to do this…when admin add new product image in media and click on insert product button the uploaded image should be added in form of shortcode into post editor.

  3. Suhail says:

    How can i add html tags like list in the content

  4. Gopi says:

    What is that 10 and 2 represents?

  5. Amita Sharma says:

    I need to add default content for specific template.

    add_filter( ‘default_content’, ‘custom_editor_content’ );
    function custom_editor_content( $content ) {
    global $current_screen;
    if ( $current_screen->post_type == ‘download’) {
    $content = ‘CONTENT FOR CUSTOM POST TYPE’;
    }
    return $content;
    }
    thanx in advance

  6. Mike says:

    Hi, this is a great tip.
    Is it possible to add default content to a taxonomy description.
    For example, every time someone makes a new Woocommerce Product Category, I would like to add a string with a shortcode and instructions into the description field.
    Thanks.

  7. Rodrigo says:

    Hi! How can I add html to the content? My content includes s and several other elements with “classes” and quotation marks. Maybe that is why the result was a blank page. Can anyone help me?

  8. Ron says:

    Thanks for the update, very helpful. How can default editor text be added to existing posts/pages? For example, if I click ‘update’ post button. This code does not allow this content to be automatically added to older posts.

  9. Arvind Gupta says:

    Can you tell how to do the same in portfolio post becuase i tried with it only add the content in post page

  10. Scot MacDonald says:

    Might this work for excerpt as well with some tweaking? I guess just swap out content for excerpt…

  11. brendan says:

    thanks! but, I’m a REAL novice at this code stuff… where within the php file do I put the code? there are so many sections within there, does it matter?

    thanks again!

  12. Dan Haddock says:

    This is an excellent tool but one thing that I was really hoping could be added would be the possibility to add this default content to posts that have already been published.

    I was just wondering is there anyway of doing this as it would be the icing on a very yummy cake?

  13. Mike says:

    How could I make this work but only for posts (ALL post types) and not for regular pages?

    • WPBeginner Support says:

      Take a look at this example:

      
      add_filter( 'default_content', 'my_editor_content', 10, 2 );
      
      function my_editor_content( $content, $post ) {
      
          switch( $post->post_type ) {
              case 'posts':
                  $content = 'your content';
              break;
              case 'stories':
                  $content = 'your content';
              break;
              case 'page':
                  $content = '';
              break;
              default:
                  $content = 'your default content';
              break;
          }
      
          return $content;
      }
      
      
  14. Jon Barnes says:

    Great! Thank you! This certainly fills the hole where a default post template should be

  15. Yorgo says:

    when i add the code above and hit the publish button , a blank page returns. The post is saved but i have to go back and continue my work. I’m running 3.6.1
    Any ideas ?
    Thanx

  16. tazo says:

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

  17. Chris G says:

    What if I only want to add default content for certain post types?

  18. AshleyBriscoe says:

    How do you add a recurring http:// url using this method, when i do the http:// starts commenting the code out

  19. gcarter1mwc says:

    Hi — this is perfect. But need one tweak. How can this be applied to one type of post only or even to a certain post?

    I’m not well-versed in php but tried the following:

    add_filter( ‘default_content’, ‘my_editor_content’ );

    function my_editor_content( $content ) { $content = “If you like this post, then please consider retweeting it or sharing it on Facebook.”; return $content; }

    function my_editor_content( $content ) {

    if ( is_page( ‘about’ )) {

    $content = “This is some custom content I’m adding to the post editor because I hate re-typing it.”;

    return $content;

    }

    }

    I don’t get an error. It simply doesn’t work. Is there a way to apply such a conditional to the function? Or, does a function do its thing with no respect to conditions?

    Thanks — Mike

  20. Coolest says:

    I have several blogs I want to try this code on. Thanks for sharing.

  21. Mick says:

    Wow, very interesting. Thanks for this post ;-)

  22. Sonu says:

    Added code snippet to my notes really helpful.

  23. Kylu says:

    Aren’t “Article Template Plugins” more useful?
    For instance: http://wordpress.org/extend/plugins/article-templates/

  24. Derek Jensen says:

    Thanks! So simple but useful!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.