Nu kan du glemme alt om spamkommentarer i WordPress 😎

Download: Glem spam kommentar plugin

Dette er et gratis anti-spam-plugin udelukkende til standardkommentarsystemet i WordPress.

Hvordan virker det?

Alternativt, for avancerede brugere, er nedenstående den manuelle metode

Standardkommentarsystemet i WordPress har to store problemer.

  1. Tiltrækning af spam-kommentarer.
  2. Ikke afsendelse af opfølgende e-mail til kommentarforfatteren (vil blive drøftet om et stykke tid).

Lad os tale om dens løsninger.

Forebyggelse af spamkommentarer

I stedet for direkte at tillade alle at lave POST-forespørgsler på /wp-comments-post.php kan vi tilføje noget logik for at forhindre spamkommentarer med 100%.

Trin 1. Begræns kommentar POST-anmodningssti over forespørgselsparameter

Jeg vil dele tre måder, brug én metode.

Apache

  • Yoast > Gå til Værktøjer > Fileditor
  • RankMath > Gå til Generelle indstillinger > Rediger .htaccess
  • FTP/SSH > Tjek /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>

Hvis du bruger LiteSpeed, understøtter den også .htaccess-filer. Du skal genstarte efter implementeringen.

NGINX

location = /wp-comments-post.php {

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

Cloudflare

prevent spam comments
  • Log ind på Cloudflare Dashboard
  • Gå til Firewall > Firewallregler
  • Opret en ny firewallregel med nedenstående udtryk
OmrådeOperatørVærdi
URIcontainswp-comments-post.phpOg
URL Query Stringdoes not equal45jpfAY9RcNeFP
  • Vælg handling: Blok

Til sidst vil du se udtryk

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

Trin 2. Korriger kommentar POST-URL’en i Scroll-begivenheden

  • Tilføj nedenstående funktion ved hjælp af Code Snippets plugin eller tema functions.php
  • Sørg for at bruge det korrekte domæne og formular-ID.
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);

Alternativt kan du tilføje ovenstående JS-del direkte ved hjælp af Elements-modulet, hvis du er bruger af GeneratePress Premium-temaet.

<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>
  • Tilføj en ny krog
  • Ny krog Titel: Ændre kommentar-URL i farten
  • Krog: WP Footer
  • Prioritet: 99
  • Placering: Indlæg – Alle indlæg
  • Udgiv

Hvordan kan jeg kontrollere, om den virker?

  • Generelt returnerer WordPress 405 svar for GET-forespørgsel på /wp-comments-post.php
  • Men efter ovenstående opsætning bør du se Access Denied (adgang nægtet).
  • Og URL’en skal kun indlæses i tilstedeværelsen af den særlige forespørgselsstreng 45jpfAY9RcNeFP, som vi har tilføjet for at forhindre spamkommentarer. Du kan ændre denne forespørgselsstreng til noget andet i alle ovenstående konfigurationer.
  • Kildekoden vil typisk vise wp-comments-post.php stien, men hvis du inspicerer elementet efter rulning vil du bemærke, at der er tilføjet en forespørgselsstreng.

Resultat #1: Ingen spam

no spam

Resultat nr. 2: Spammere bliver blokeret

log

Bonustip til at gøre standardkommentarsystemet endnu bedre

  • Som standard sender WordPress’ kommentarsystem ikke en opfølgende e-mail til kommentarforfatteren. For at løse dette problem kan du bruge Comment Reply Email Notification plugin af Arno Welzel.

Hvis du kan lide disse oplysninger, bedes du give dem videre til dine venner. 🙏

Skriv en kommentar

20 kommentarer til “Nu kan du glemme alt om spamkommentarer i 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.

    Svar
  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?

    Svar
  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)?

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

    Svar
    • 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!

      Svar