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

Hinzufügen von Standardinhalten im WordPress-Post-Editor

Hinweis der Redaktion: Wir erhalten eine Provision für Partnerlinks auf WPBeginner. Die Provisionen haben keinen Einfluss auf die Meinung oder Bewertung unserer Redakteure. Erfahre mehr über Redaktioneller Prozess.

Haben Sie sich schon einmal dabei ertappt, dass Sie in allen Ihren Beiträgen denselben Text eingeben? Oft wird das gemacht, z. B. um Leute aufzufordern, ihre Feeds zu abonnieren, den Beitrag zu retweeten, ihn auf Facebook zu teilen usw. Sie können immer einen einfachen Tag verwenden, um ihn direkt nach dem Inhalt hinzuzufügen, oder Sie können diesen Text als Standardinhalt in Ihrem WordPress-Post-Editor hinzufügen.

Öffnen Sie einfach die Datei functions.php Ihres WordPress-Themes und fügen Sie den folgenden Code ein, natürlich innerhalb der PHP-Tags.

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

Und schon sind Sie fertig. Versuchen Sie, einen neuen Beitrag zu erstellen, und Sie sollten den neuen Inhalt dort sehen.

Update (24. Januar 2013) – Einer unserer Nutzer fragte uns in den Kommentaren, wie man unterschiedliche Inhalte für verschiedene Beitragstypen hinzufügen kann. Der folgende Code zeigt Ihnen, wie Sie in Ihrem WordPress-Beitragseditor für jeden spezifischen benutzerdefinierten Beitragstyp unterschiedliche Standardinhalte hinzufügen können:

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

Quelle: Justin Tadlock

Offenlegung: Unsere Inhalte werden von unseren Lesern unterstützt. Das bedeutet, dass wir möglicherweise eine Provision verdienen, wenn Sie auf einige unserer Links klicken. Mehr dazu erfahren Sie unter Wie WPBeginner finanziert wird , warum das wichtig ist und wie Sie uns unterstützen können. Hier finden Sie unseren redaktionellen Prozess .

Das ultimative WordPress Toolkit

Erhalte KOSTENLOSEN Zugang zu unserem Toolkit - eine Sammlung von WordPress-bezogenen Produkten und Ressourcen, die jeder Profi haben sollte!

Reader Interactions

47 KommentareEine Antwort hinterlassen

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. John M Brooks says

    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 says

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

      Admin

    • Jack says

      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

  3. sp says

    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

  4. Dan Jones says

    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

  5. 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.

  6. 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.

  7. 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

  8. 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.

  9. 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?

  10. 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.

  11. Scot MacDonald says

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

  12. 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!

  13. 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?

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

      Admin

  14. 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

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

  16. AshleyBriscoe says

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

  17. 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

Eine Antwort hinterlassen

Danke, dass du einen Kommentar hinterlassen möchtest. Bitte beachte, dass alle Kommentare nach unseren kommentarpolitik moderiert werden und deine E-Mail-Adresse NICHT veröffentlicht wird. Bitte verwende KEINE Schlüsselwörter im Namensfeld. Lass uns ein persönliches und sinnvolles Gespräch führen.