Vergeet nu Spam Commentaar in WordPress 😎

Download: Forget Spam Comment Plugin

Dit is een gratis anti-spam plugin uitsluitend voor het standaard commentaarsysteem van WordPress.

Hoe werkt het?

Als alternatief, voor gevorderde gebruikers, volgt hieronder de handmatige methode

Het standaard commentaarsysteem van WordPress heeft twee grote problemen.

  1. Het aantrekken van spam commentaren.
  2. Geen follow-up e-mail sturen naar de auteur van het commentaar (zal het over een tijdje bespreken).

Laten we het hebben over de oplossingen.

Spam reacties voorkomen

In plaats van iedereen direct toe te staan een POST-verzoek te doen op /wp-comments-post.php kunnen we wat logica toevoegen om spamcommentaren voor 100% te voorkomen.

Stap 1. Beperken Commentaar POST verzoek Pad over Query Parameter

Ik ga drie manieren delen, gebruik één methode.

Apache

  • Yoast > Go to Tools > File Editor
  • RankMath > Go to General Settings > Edit .htaccess
  • FTP/SSH > Check /var/www/html
# If Query string doesn't matches return 404
<IfModule mod_rewrite.c>
	RewriteEngine On
        RewriteCond %{REQUEST_URI} .wp-comments-post\.php
        # You may change 45jpfAY9RcNeFP to something else
        RewriteCond %{QUERY_STRING} !^45jpfAY9RcNeFP
	RewriteRule (.*) - [R=404,L]
</IfModule>

Als u op LiteSpeed bent, steunt het ook .htaccess bestand. U moet opnieuw opstarten na implementatie.

NGINX

location = /wp-comments-post.php {

 if ($query_string !~ "45jpfAY9RcNeFP") {
     return 404;
  }
}

Cloudflare

prevent spam comments
  • Inloggen op Cloudflare Dashboard
  • Ga naar Firewall > Firewall Rules
  • Maak een nieuwe firewall regel met onderstaande uitdrukking
FieldOperatorValue
URIcontainswp-comments-post.phpAnd
URL Query Stringdoes not equal45jpfAY9RcNeFP
  • Kies actie: Blok

Aan het eind zie je uitdrukking

(http.request.uri contains "wp-comments-post.php" and http.request.uri.query ne "45jpfAY9RcNeFP")

Stap 2. Corrigeer de Commentaar POST URL op Scroll evenement

  • Voeg onderstaande functie toe met behulp van Code Snippets plugin of thema functions.php
  • Zorg ervoor dat u het juiste domein en formulier ID gebruikt.
function correct_comment_url_on_scroll() {
// Check if Comment is enabled
if(comments_open()) echo '<script>
let commentForm = document.querySelector("#commentform, #ast-commentform, #ht-commentform");

// Load new comment path on the scroll event
document.onscroll = function () {
    commentForm.action = "https://www.example.com/wp-comments-post.php?45jpfAY9RcNeFP";
};
</script>';
}
add_action('wp_footer', 'correct_comment_url_on_scroll', 99);

Als alternatief, als u een GeneratePress Premium thema gebruiker bent, kunt u bovenstaand JS deel direct toevoegen met de Elements module.

<script>
let commentForm = document.querySelector("#commentform");

commentForm.action = "https://www.example.com/wp-comments-post.php";
// Load new comment path on the scroll event
document.onscroll = function () {
    commentForm.action = "https://www.example.com/wp-comments-post.php?45jpfAY9RcNeFP";
};
</script>
  • Voeg een nieuwe hook
  • Nieuw Hook Titel: Verander de URL van het commentaar in de lucht
  • Hook: WP Footer
  • Prioriteit: 99
  • Locatie: Berichten – Alle berichten
  • Publiceren

Hoe controleer je of het werkt?

  • Over het algemeen stuurt WordPress een 405 antwoord terug voor een GET verzoek op /wp-comments-post.php
  • Maar na bovenstaande instelling zou u Toegang geweigerd moeten zien.
  • En de URL mag alleen worden geladen in aanwezigheid van de speciale querystring 45jpfAY9RcNeFP die we hebben toegevoegd om spamreacties te voorkomen. U kunt deze querystring wijzigen in iets anders in alle bovenstaande configuraties.
  • De broncode toont meestal het pad wp-comments-post.php, maar als u het element na het scrollen inspecteert, ziet u dat er een query string is toegevoegd.

Resultaat #1: Geen Spam

no spam

Resultaat #2: Spammers worden geblokkeerd

log

Bonustip om standaard commentaarsysteem nog beter te maken

  • Standaard stuurt het commentaarsysteem van WordPress geen e-mail naar de auteur van het commentaar. Om dit probleem op te lossen kun je de plugin Comment Reply Email Notification van Arno Welzel gebruiken.

Als deze informatie u bevalt, geef het dan door aan uw vrienden. 🙏

Gerelateerde berichten

Plaats een reactie

20 gedachten over “Vergeet nu Spam Commentaar in WordPress 😎”

  1. Thank you so much Sir Gulshan Kumar! I really appreciate your guide, and this has saved me tons of headache. Implemented via Cloudflare WAF plus Generatepress Elements Module.

    Beantwoorden
  2. By the way, how do you know if legit users won’t get blocked? Before this, I’ve been using a CF firewall rules that will blocks or challenge anyone who visit wp-comments-post.php but actually by doing so, legit users also got blocked. How this one different? Is it because of the string “45jpfAY9RcNeFP” that will differentiate which request is from bot and which request is from legit users? If legit users, they should’ve the string, if it’s spam, they don’t have that string. Am I understand it correctly?

    Beantwoorden
  3. Does this plugin / method will stop website from having spam comments once and for all or do we still receive it but it’s automatically filtered from the real comments (like Akismet)?

    Beantwoorden
  4. Hi Gulshan.

    I just wanted to let you know that I’ve been using your plugin for a few weeks now and it is brilliant. Genuine comments still get through but all of the spam, and I mean ALL of it, is filtered out. Excellent job!

    Well done and thank you so much for sharing it for free so that hobby bloggers like me can make use of it.

    Beantwoorden
    • Hi,
      I am also using plugin at this blog. It works perfectly fine here.
      If you want to me look into this issue, please provide your actual site URL where I can see live.
      Thanks!

      Beantwoorden