[Support request] Spam Prevention in Comments

Home Forums Support [Support request] Spam Prevention in Comments

Home Forums Support Spam Prevention in Comments

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #976452
    Holley

    Hoping you can help me out with a little spam prevention. I’ve tried adding the following code to my GeneratePress child theme functions.php to disable the comments URL/website field and to disallow html in the comments section to try and cut down on spam comments but it doesn’t seem to be working. I see in /structure/comments.php there is some customization going on with the comments section, maybe that’s conflicting?

    Disable URL field:

    add_filter('comment_form_default_fields', 'unset_url_field');
    function unset_url_field($fields){
    if(isset($fields['url']))
    unset($fields['url']);
    return $fields;
    }

    Disallow html

    function wpb_comment_post( $incoming_comment ) {
    $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
    $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
    return( $incoming_comment );
    }
    function wpb_comment_display( $comment_to_display ) {
    $comment_to_display = str_replace( ''', "'", $comment_to_display );
    return $comment_to_display;
    }
    add_filter( 'preprocess_comment', 'wpb_comment_post', '', 1);
    add_filter( 'comment_text', 'wpb_comment_display', '', 1);
    add_filter( 'comment_text_rss', 'wpb_comment_display', '', 1);
    add_filter( 'comment_excerpt', 'wpb_comment_display', '', 1);
    remove_filter( 'comment_text', 'make_clickable', 9 );
    #976523
    David
    Staff
    Customer Support
    #977534
    Holley

    Ah, perfect thanks.

    How about for not allowing html in the comment field?

    #977545
    Leo
    Staff
    Customer Support

    Maybe something like this?
    https://stackoverflow.com/questions/18168352/disabling-html-on-comments

    If not you might need to check with WordPress.

    HTML is generally allowed in comments as it doesn’t really prevent spam or cause harm in your site.

    #977547
    Holley

    Just trying to cut down on bots posting links in the comments. I’ll try that, thx!

    #977599
    Leo
    Staff
    Customer Support

    No problem 🙂

    #977753
    Jim

    Try AntiSpam Bee plugin instead. With Akismet, I usually see spam comments with URLs go through even with comment URL field disabled. But the plugin does not work with contact forms, so you might have to use google recaptcha with those. But it is vry effective and I have never received spam comments since I began using it.

    #978215
    Leo
    Staff
    Customer Support

    Thanks for sharing!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.