The site constantly flies spam in the comments. I don’t know much about WP (I understand that everything should be done in function.php so that it doesn’t disappear after the update), so tell me how to add a hidden field for the comments form, but because spam doesn’t go directly to my site ( mailing is)

  • If you are not familiar with WP, then it is better not to interfere with functions.php. Is the Akismet plugin worth it? It is usually enough. - KAGG Design
  • I am not familiar with WP, but I am familiar with php. I just need to know how fields are inserted in this engine, through which function and syntax. Plugins - too much. - Sarkis Allahverdian
  • You still have to create your plugin so that when updating wp you do not edit the files. - Visman
  • one
    @SarkisAllahverdian, 1. Plugins are not superfluous - but the right way to customize the functionality . Just in order, "so that after the update does not fly away." 2 Akismet really helps spam. 3. If not akismet, then you have to write your own plugin. Php knowledge is not enough here. Need knowledge of VP deeper than that of a housewife. - SeVlad
  • > (as I understand it, everything should be done in function.php. If function.php , then not the VP, but the themes. Moreover, the subsidiary is SeVlad

1 answer 1

You must use the comment_form_default_fields hook.

In functions.php child theme, add something like this:

 add_filter( 'comment_form_default_fields', 'add_field' ); function add_field( $fields ){ $fields['my_hidden_field'] = '<p class="comment-form-my-hidden">' . '<label for="my-hidden">' . 'My hidden field' . '</label> ' . '<input id="my_hidden_field" name="my_hidden_field" type="hidden" value="" size="30" /></p>','; return $fields; } 

This will create an additional field in the form of comments, which you can then process yourself or analyze the comment using the pre_comment_approved filter.

 add_filter( 'pre_comment_approved', 'filter_function_name_11', 10, 2 ); function filter_function_name_11( $approved, $commentdata ){ // проанализировать комментарий и // вернуть 0, 1 или 'spam' return $approved; }