Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPress投稿エディターに初期設定コンテンツを追加する方法

投稿にすべて同じ文章を入力していることに気づいたことはないだろうか。フィードを購読してほしい、投稿をリツイートしてほしい、facebookでシェアしてほしい、などなど。シンプルなタグを使ってコンテンツのすぐ後に追加したり、WordPressの投稿エディターで初期設定としてそのテキストを追加することができます。

WordPressテーマのfunctions.phpファイルを開き、PHPタグ内に以下のコードを貼り付けるだけです。

[cbk1]

これで完了です。新規投稿を作成してみると、新しいコンテンツが表示されるはずです。

更新(2013年1月24日)– あるユーザーから、投稿タイプごとに異なるコンテンツを追加する方法をコメントで尋ねられました。以下のコードでは、WordPress投稿エディターで特定のカスタム投稿タイプごとに異なる初期設定コンテンツを追加する方法を紹介します:

[cbk2]

ソースジャスティン・タドロック

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

アバター

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

46件のコメント返信を残す

  1. Jose

    what if i want my default content to be a table with rows & columns on the Editor

  2. Mehedi Hassan

    But where the code will pasted. I cant paste the code in actual place in function.php. please help.

    • WPBeginner Support

      For this specific post, you would need to add it to your functions.php

      管理者

  3. ankit goyal

    How we can Add Default Content in woocommerce short description Editor

    • WPBeginner Support

      You would want to check with WooCommerce for their current method to do that :)

      管理者

  4. John M Brooks

    Any chance this will be updated for Gutenberg? As it stands, it currently adds the content to a “classic editor” block.

    Regardless, I appreciate this post. Thank you.

    • WPBeginner Support

      We are in the process of going through different articles for Gutenberg/Block editor compatibility. We’ll be sure to take a look at this one :)

      管理者

  5. tuấn

    That code can add content before or bellow content admin?

  6. Aaliyan Mehmood

    Thanks for this good tip. You made my work easy.
    Thanks a lot.

  7. Mark

    how can I make this appear in the end of each post instead of beginning

    • Jack

      I am not able to do it at the first place let alone at the beginning. Can you help guide me. Where exactly did you posted the code. The code is okay. Functions.php is okay., but placement of this is a challenge. Not able to figure out where to paste

  8. David Keith

    Thanks! This worked brilliantly. *cheers!*

  9. sp

    thanks 4 the post but i want little more like i want to add code content like a small code that i can use in all post and can edit some of its vale for each post, like i want some text in bold some coloured text one youtube embeded code where i can just change video link …please help me soon with the process

  10. lammy

    how can i add default message to all my posts just immediately after post title

  11. Amri

    can i get list tags or categories with this?

  12. Dan Jones

    Hi,

    Thanks for the code.

    Is it possible to add custom text to a post so it’s stored within the post on publishing?

    Thanks,

    Dan

  13. Grant Skinner

    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.

  14. Krishna

    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.

  15. Suhail

    How can i add html tags like list in the content

  16. Gopi

    What is that 10 and 2 represents?

  17. Amita Sharma

    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

  18. Mike

    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.

  19. Rodrigo

    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?

  20. Ron

    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.

  21. Arvind Gupta

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

  22. Scot MacDonald

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

  23. brendan

    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!

  24. Dan Haddock

    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?

  25. Mike

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

    • WPBeginner Support

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

      管理者

  26. Jon Barnes

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

  27. Yorgo

    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

  28. tazo

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

  29. Chris G

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

  30. AshleyBriscoe

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

  31. gcarter1mwc

    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

  32. Coolest

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

  33. Mick

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

    • Ahtisham

      it is very intesting…. and cool… thanks

  34. Sonu

    Added code snippet to my notes really helpful.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。