Rules to send a comment comment reply. WordPress Comment Template

Those who comment on me will immediately understand what I am writing about. After you receive a response to your comment, you receive a notification by email (it does?), they say, so and so, a response was received on the site and all that, if, of course, you left your real email.

Read below about how this is implemented.

For example, I am a frequent guest on many blogs and actively communicate on them in the comments. And it is unrealistic to retain all the threads of conversations, remembering on which blogs and in what topics the correspondence was conducted. Therefore, if I suddenly commented on someone, you answered me, and I, in turn, did not react in any way - then I apologize, but it’s your own fault - you should have taken care of automatic notification by mail, and at the same time increasing the number of comments on your articles.

And in this case, everyone’s favorite Subscribe to Comments plugin is far from the best option, because it allows you to subscribe to all new comments on an article. I don’t know about you, but personally, it’s annoying for me to clear out the rubble in the mail (I have to sort through several hundred letters a day anyway), when you subscribe to your head like this on some commented blog) Therefore, I almost never use this function, even though This plugin is worth it to me.

UPD. They delicately turned me off in the comments, reminding me that in this plugin it is also possible to enable the choice of subscription option - for all messages or only for replies. However, I forgot about it for a reason, the fact is that I had already tested this feature once and thus the notifications in the mail did not reach me at all. I don’t know what the problem was, but I thought that this function did not work normally. By the way, almost no one turns it on or even knows about the existence of such an opportunity, so in most cases on blogs you only need to subscribe to all comments on an article.

And that’s half the problem - you could say that you signed up, which means it’s your own fault, you knew what you were getting into, you checked the box - clean it up now (or didn’t remove it, if it’s checked by default) :)

But there are such smart-ass blogs, including among my friends (I won’t point fingers :) where site owners check this box by default, and then simply remove it from the page.

Those. thus, by leaving your comment on this site, you automatically become the happy owner of a subscription to all comments on the article (which most people don’t care about, we are primarily interested in our own person) and, at the same time, shitting on the mail =)

Well, well, well, nonono! It’s not good to do this and force such a subscription on people - I’m sure many people are annoyed by sudden blockages in the mail. For example, I immediately unsubscribe from such a mailing list, and in the future I will think several times about whether it’s worth leaving comments on such a blog at all, so as not to bother myself with unnecessary cleaning up later.

There should be freedom of choice, at least on the Internet, whoever wants to will subscribe, if I want to read other people’s comments, I’ll go and read them on the blog myself. I understand that this is also a marketing technique to increase traffic to the resource, attract users to discussions, etc. however, it seems to me that the technique is very dubious and can give the opposite result.

I hope my call will be heard - return the check mark, down with coercion! 🙂

Comment Reply Notification plugin.

Here he is, this little scoundrel, which, for some reason, few people know about, or know, but do not use. But this is a great way to remind the commentator about your blog and get him to return as soon as possible, thereby maintaining the thread of the conversation and improving behavioral factors.

It was suggested to me by my comrade in arms and just a good blogger Evgeniy fishkalife. Still, I can’t resist and sleep - before he also had a forced subscription to comments, which really infuriated me :) But then he installed this useful plugin, and commenting on his blog became much more pleasant, especially since there is something to comment on =)

The meaning of its work is simple - as soon as you receive a response to your comment, you receive a notification letter in the mail, and only when the answer is personal to your message - it’s called feel the difference with the buggy Subscribe to Comments :) As a result, the mail is in order, and the mission is completed - the visitor is happy that they are talking to him and even politely reminding him of this, so that he does not have to strain himself once again to keep everything in his memory.

I won’t describe the plugin settings in detail, I think they are no longer small, they are elementary - we chose in which cases to inform about the response, configured the text of the notification letter (it is advisable to do everything in Russian, of course) and that’s all, we enjoy the increased commentary on the blog) If If someone still has problems - write in the comments.

Upd: I didn’t manage to freeload) Due to numerous requests, I’ll briefly write how to translate the line in this plugin that displays a checkbox with a subscription to a reply.

It appears after installing the plugin, go to its settings and enable Commenter choose to do so (default checked) in the settings, if we want to give the visitor the right to choose whether he wants to receive a response to his comment by mail (although here you can safely select “If the response is from post author or administrator" or "Always inform")

Under the comment form, the following message will appear: “Notify me of follow-up comments via e-mail”, which it would be desirable to translate. This is done directly in the comment-reply-notification.php plugin file.

Just open it in a text editor, find the phrase through the search Notify me of follow-up comments via e-mai and in 2 places we replace it with the one we need, for example Notify me of a response to my comment by email. Close, save, everything is ready)

By the way, I myself do not have this plugin installed separately, but this function is built into another - the WordPress Thread Comment tree comment plugin - it’s like in advertising, 2 in 1, a universal solution for those whose templates do not support the possibility of tree comments and who want to set up an alert about replies to mail.

By the way, you probably noticed that even with this plugin I give the person the right to choose whether he wants to receive notifications by email.

Although it’s not so scary here, if this option is removed, at least there won’t be any blockages at the post office.

What plugin do you use to notify your commenters?

WordPress has several types of content such as posts, pages, comments. WordPress is a very flexible platform that allows you to customize basic content to suit your site. You can change the appearance and functionality. In this tutorial we will show you how to change the behavior and appearance of comments on a WordPress site.

Step 1. Understanding the comment_form function and its arguments

Let's take a look at the WordPress comment_form function. It is responsible for displaying the comment form that appears on the page or post. The call to this function can mainly be found in the comments.php file in the theme folder. This file is included in various places, for example in the single.php and page.php files, directly or through a call to the comments_template function.

Description of the function can be found in the WordPress codex.

If you use the comment_form function to display a form, it will be rendered using the default parameters and will contain fields such as name, email (both fields are required), website, and comment content. In the default Twenty Eleven theme, the form will look like this.

Some important arguments to the comment_form function:

  • fields - you can use it to control the display of fields in the comment form.
  • comment_notes_before and comment_notes_after - used to display information before and after the form.
  • title_reply - used to change the title of the reply, which defaults to ‘Leave a Reply’.
  • label_submit - used to change the text on the comment submit button.
Step 2. Customize the comment form using the comment_form function

Now let's set up our comment form by passing arguments to the comment_form function.

In case we need to customize the fields in the comment form, we need to pass a list of them to the comment_form function. By default, the function uses the following list of fields:

$fields = array("author" => "

" . "" . __("Name") . " " . ($req ? "*" : "") . "

", "email" => " ", "url" => "

" . __("Website") . "" . "

",);

If we need to remove a field, for example website , we simply need to exclude it from the array and pass the array to the comment_form function.

$commenter = wp_get_current_commenter(); $req = get_option("require_name_email"); $aria_req = ($req ? " aria-required="true"" : ""); $fields = array("author" => "

" . "" . __("Name") . " " . ($req ? "*" : "") . "

", "email" => " ",); $comments_args = array("fields" => $fields); comment_form($comments_args);

In addition, we will also change the name of the form to ‘Please give us your valuable comment’, and the inscription on the button to ‘Send My Comment’.

To complete the task, we pass the following arguments to the comment_form function:

$commenter = wp_get_current_commenter(); $req = get_option("require_name_email"); $aria_req = ($req ? " aria-required="true"" : ""); $fields = array("author" => "

" . "" . __("Name") . " " . ($req ? "*" : "") . "

", "email" => " ",); $comments_args = array("fields" => $fields, "title_reply"=>"Please give us your valuable comment", "label_submit" => "Send My Comment"); comment_form($comments_args);

Now the comment form will look like this:

Step 3. Removing fields from a form using a hook

Also, the WordPress comment form can be modified using hooks and filters. This setting can be especially useful when working with a plugin, when you need to customize several elements, but not change the theme files. Filter for adding or removing fields from the form - ‘ comment_form_default_fields ‘

Let's remove the URL field using a filter. The above code can be used in a plugin or in the functions.php file of the active theme.

Function remove_comment_fields($fields) ( unset($fields["url"]); return $fields; ) add_filter("comment_form_default_fields","remove_comment_fields");

Step 4. Add data to the comment form using a hook

We can add fields to the form using the ‘comment_form_default_fields’ filter. Let's add the author's age field using a filter and save this field with additional data and display it in the comment.

Add a field like this:

Function add_comment_fields($fields) ( $fields["age"] = "

" . __("Age") . "" . "

"; return $fields; ) add_filter("comment_form_default_fields","add_comment_fields");

#respond .comment-form-author label, #respond .comment-form-email label, #respond .comment-form-url label, #respond .comment-form-age label, #respond .comment-form-comment label ( background: #eee; -webkit-box-shadow: 1px 2px 2px rgba(204,204,204,0.8); -moz-box-shadow: 1px 2px 2px rgba(204,204,204,0.8); box-shadow: 1px 2px 2px rgba(204,204,204, 0.8); color: #555; display: inline-block; font-size: 13px; left: 4px; min-width: 60px; padding: 4px 10px; position: relative; top: 40px; z-index: 1; )

Now our comment form will look like this:

Age is now stored as additional information. You need to use the hook in ‘comment_post’:

Function add_comment_meta_values($comment_id) ( if(isset($_POST["age"])) ( $age = wp_filter_nohtml_kses($_POST["age"]); add_comment_meta($comment_id, "age", $age, false); ) ) add_action("comment_post", "add_comment_meta_values", 1);

Once the data is saved, it can be output as a comment like this:

Step 5. Setting up comments for specific post types

Sometimes you want to use comment fields only for certain types of posts. Let's change the code to display the age field only for a book record type:

Function add_comment_fields($fields) ( if(is_singular("books")) ( $fields["age"] = "

" . __("Age") . "" . "

"; ) return $fields; ) add_filter("comment_form_default_fields","add_comment_fields");

Step 6. Create a callback function to display comments

The wp_list_comments function is used to display comments on posts. In the WordPress code the function is described in detail.

wp_list_comments has a ' callback ' argument in which you can define a function that is called when a comment is displayed.

In the Twenty Eleven theme in the comments.php file you can find the line:

Wp_list_comments(array("callback" => "twentyeleven_comment"));

Let's change it to:

Wp_list_comments(array("callback" => "my_comments_callback"));

The my_comments_callback function will be called for each post.

Step 7: Styling Comments

Now we'll change the comment style a little. We will simply display the contents of the post and the age field that we added earlier. We will also change the background color for comments.

Function code ‘my_comments_callback’:

Function my_comments_callback($comment, $args, $depth) ( $GLOBALS["comment"] = $comment; ?>

For a description and accepted arguments of the comments_template() function and others mentioned in the article, look in the WordPress Codex.

Preparing the template

Let's try to understand WP comment templates and make our own file for displaying comments on blog posts and pages. As examples for reference, you can take templates from standard WordPress themes. Let's create a new document in any text editor, call it comments.php and start editing.

  • In principle, you can name the file anything you like, and then write the path to this file in comments_template(), but it is better to stick to the standard name
  • You can also edit the file in the WP admin panel, by the way.
  • It is best, of course, to write code and immediately test its effect on your blog or on a local server.

In WordPress it is possible to disable comments for individual posts, so before displaying them you need to check for “openness”:

This is a wrapper code for our further actions. Now let’s prepare a container for the comment block with a semantically correct class or identifier (class is of course preferable):

We’ll write a title inside so that your readers understand that there are comments here and nothing else, the tag will be just right for this:

"

Here we have indicated one of the WordPress functions - the_title(), the result of executing this function will be the output of the title of the current post or page. If you do not want to display the title, you can simply write “Reader Comments”.

Next, before displaying comments, you need to make sure they exist, i.e. check, if there is, display the full list, if not, then you can show the user something like “”. This way, it will be clear to the visitor to your post/page that no one has written anything yet, and the motivating phrase “You can be the first” will increase the likelihood that they will write something to you faster.

So, after this formulation of the problem, it becomes clear that for implementation we will need if/else constructs and a function for displaying the number of comments get_comments_number() . If the function returns 0 (zero), then we display “No comments yet...”, otherwise “Reader comments...”:

There are no comments yet, but you can be the first Reader comments on the article "" Discussions are closed for this page

Outputting comments

Great, we have displayed the headings depending on the presence or absence of comments, now it is logical to display the comments themselves - the wp_list_comments() function is responsible for this. The default function wraps all comments in tags

  • , so you should add a wrapper with class assignment.commentlist:

    wp_list_comments() takes an array of arguments that can be used to flexibly customize the display of comments. For example, you can change the avatar size, comment reply text, and other settings by passing a keyword and value:

    $args = array("avatar_size" => 64, // avatar size 64*64px, default 32 "reply_text" => "Reply" // text of the response to the comment "callback" => "my_comments" // function for generating an external type of comment)

    The callback parameter deserves special consideration, which takes the value of the name of a custom function for displaying a comment. With its help, you can flexibly customize the appearance of each comment. This is what the standard output function looks like from the comment-template.php file: