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

Wie man HTML in WordPress-Kommentaren ausschaltet

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.

WordPress lässt standardmäßig bestimmte HTML-Tags in den Kommentaren zu, z. B. <a> <em> <strong> usw. Sie werden feststellen, dass viele SPAM-Kommentare auch diese Tags enthalten. Die meisten SPAM-Kommentare werden von Bots und Skripten erstellt, die HTML-Tags verwenden. Wenn Sie einfach HTML in Ihren WordPress-Kommentaren deaktivieren, können Sie eine Menge SPAM verhindern. In diesem Tutorial zeigen wir Ihnen, wie Sie HTML-Tags in Ihren WordPress-Kommentaren deaktivieren können.

In dieser Anleitung werden nur aktive HTML-Tags deaktiviert. Es kann also immer noch jemand etwas posten wie:

&lt;a&gt;&lt;em&gt;&lt;strong&gt;

Es wird zwar angezeigt, aber die Tags sind dann nicht mehr aktiv. Wenn also jemand das strong-Tag verwendet, wird der Text nicht fett dargestellt. Außerdem haben nicht viele SPAM-Bots die Zeit, dies zu tun, da dieser Weg viel Zeit in Anspruch nimmt und für sie nicht von Vorteil ist.

Alles, was Sie tun müssen, ist, Ihre functions.php zu öffnen und den folgenden Code einzufügen:

    // This will occur when the comment is posted
    function plc_comment_post( $incoming_comment ) {

    // convert everything in a comment to display literally
    $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

    // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
    $incoming_comment['comment_content'] = str_replace( "'", '&apos;', $incoming_comment['comment_content'] );

    return( $incoming_comment );
    }

    // This will occur before a comment is displayed
    function plc_comment_display( $comment_to_display ) {

    // Put the single quotes back in
    $comment_to_display = str_replace( '&apos;', "'", $comment_to_display );

    return $comment_to_display;
}

Wenn Sie diesen Code nicht selbst einfügen möchten, bietet der Originalautor auch ein Plugin an, das Sie herunterladen können. Installieren und aktivieren Sie einfach Peter’s Literal Comments Plugin.

Der Grund, warum dieser Weg besser ist, ist, dass Sie die Kerndateien nicht ändern müssen. Wenn Sie Ihre Kerndateien bearbeiten möchten, können Sie zu wp-includes/kses.php gehen und die Codes dort bearbeiten. (Dies wird nicht empfohlen, soll aber hier nur der Übersichtlichkeit halber erwähnt werden.(WP Codex für weitere Einzelheiten)

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

24 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. Gwyneth Llewelyn says

    Unfortunately, the Peter’s Literal Comments plugin is not active any longer; it has been updated last in 2015, and may not even work on recent versions any more. You might need to recommend a different plugin instead…

    • WPBeginner Support says

      Thank you for letting us know that the plugin is not active a the moment. When we look at updating the article we will look for an alternative :)

      Admin

    • WPBeginner Support says

      Hi,

      You can use the following HTML tags in comments by default.

      <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

      Admin

  3. anshu says

    there are lots of commnts on my every blog post … how to disable HTML hyperlink so that i can prevent my blog post from spam

  4. falvarez says

    I think that something is missing. You should add your function plc_comment_display() to the filter stack like this:

    add_filter(‚comment_text‘, ‚plc_comment_display‘);

    Regards.

  5. johnroypaul says

    Brilliant article thanks! Seems to work perfectly well with the latest versions of wordpress as well (3.3) Made the code a lot cleaner as mentioned and seems to have made life easier when trying to implement the comments form into side areas ect. (Had a nightmare with previous use of the normal code)

  6. wordpress hosting says

    The more mature you are, the harder at risk you are for getting something undesirable happen to you while overseas. Thanks for revealing your suggestions on this blog.You have good grapes on wordpress thanks for making my problem so easy .

  7. Cruz3N says

    Its confused me Bro, but i make some simple plugin that allow you to replace with &gt ;

    <?php
    /*
    Plugin Name: Filter Comments
    Plugin URI: http://cruzenaldo.com/plugin-sederhana-filter-komentar/
    Description: Plugin sederhana untuk melakukan filterisasi terhadap komentar dan mencegah user menginput tag – tag HTML
    Author: Cruz3N
    Author URI: http://www.cruzenaldo.com/
    Version: 1.0
    */

    function my_function ($text) {
    $text = str_replace('‘, ‚&gt ;‘, $text);
    return $text;
    }

    add_filter(‚comment_text‘, ‚my_function‘);
    ?>

    You can modification that better… Hope usefull

    Download here
    http://www.box.net/shared/rgb4lmt5uy

    And this is my ugly blog :p
    http://cruzenaldo.com/

    Best Regard
    Cruz3N

  8. Infographiste says

    Thank you for the useful tuto and easy to follow. I’ve found another one explaining how to disable HTML but was to hard and badly explained, anyway thanks again and have a great week end :)

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.