Black Friday sale! Get up to 25% off GP Premium! Learn more ➝

[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
  • #976452

    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){
    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 );
    Customer Support

    Ah, perfect thanks.

    How about for not allowing html in the comment field?

    Customer Support

    Maybe something like this?

    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.


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

    Customer Support

    No problem 🙂


    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.

    Customer Support

    Thanks for sharing!

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