This name does not bother many people, but sometimes the question arises of how to change add a comment to leave a review or the like. In this case, this article will help you. As I wrote above, I’ll show you a couple of ways.

Method No. 1

For the first method, you must find the comments.php file in the folder with the theme that is installed on your site. If there is one, open it and look in it for the array responsible for setting up and displaying the contents of the comment form. It looks something like this:

$args = array("comment_notes_before" => "

", "comment_field" => "

A comment *

", "id_submit" => "comm_subm", "label_submit" =>

So, to this array, you need to add new parameter with the desired value and that's it. In our case, this is:

"title_reply" => "Leave your review",

As you understand - Leave your review, this is the new name instead of - Add a comment. You can add such a parameter at the end or at the beginning of the array. It will turn out something like this:

$args = array("title_reply" => "Leave your review", "comment_notes_before" => "

Fill out the fields below. Your email will not be published. Required fields are marked *

", "comment_field" => "

A comment *

", "id_submit" => "comm_subm", "label_submit" => "Submit",); comment_form($args);

Added to the beginning and now, on the post pages the line will be displayed - Leave your review. This method is not complicated and requires minimal effort, the main thing is to correctly define the array. But sometimes it happens that there is no comments.php file inside the theme or there is no array in it and you don’t know how to add it there correctly, then the second method will help you.

Method No. 2

The essence of the second method is to add a new function, which will replace the name. To do this, in the folder with the active theme, you need to find the function.php file with custom functions and in comfortable spot, if you don’t know this, then at the very end before the closing PHP tag - ?> , if there is no such thing, then just at the very end, add this code:

Function wph_change_submit_label($defaults) ( $defaults["title_reply"] = "Leave your review"; return $defaults; ) add_filter("comment_form_defaults", "wph_change_submit_label");

Bonus

This is essentially the same as what was done in the first method, simply, there we implemented it directly into the array, and here through a filter. After these steps, you will see a change in the name. As in the first method, you can change the text - Leave your review to the one you like. This text is provided as an example.

I also want to suggest and draw attention to the declension of the word Comments. If your form displays the line - 1 comment published or Comments: 10. You can use the Function from the article. If you already use it, I recommend in a line with an array:

Array("comment","comment","comments")

Change the names to review, review, reviews if you used this word in the methods above. this way, you will have everything the same, and not scattered, there are reviews and there are comments.

This is the information I wanted to provide you with today. Perhaps it will be useful to someone.

That's all, thanks for your attention. 🙂

To be honest, when I saw that they were writing about this and advising newcomers on other sites, I was a little horrified and decided to write down my note on this topic without a fatal flaw. Mostly I saw long sheets of code that implement adding comments to the site. Usually, for this purpose, they create a form, implement its processing, saving, as well as selections for display. But the advantages of this approach become less and less as time goes on.

In this post you will learn one of the simplest (but, subjectively, one of the most preferable) ways to add comments to a site - a simple example for beginners + options for more advanced webmasters.

Indeed, why reinvent the wheel and write a bunch of code that will still have to be supported, fixed, etc. in the future, if there is a bunch ready-made solutions from third-party services (we are talking about in social networks+disqus)?

But before we move on to implementation itself, let's look at the advantages/disadvantages of using ready-made solutions. (If you forgot about anything, write in the comments and we’ll expand the list)

Benefits of third-party solutions:

  • Easy to implement.
  • Protection against spam “out of the box” (in my solution I would have to additionally implement this, so, theoretically, it is related to the previous point).
  • Less prone to errors, bugs, etc., since third-party solutions have been tested by millions of users (again related to the first: you can also write everything without bugs, but it will take additional time to debug).
  • As a rule, services provide a ready-made admin panel, statistics, notifications for admins, sometimes moderation, several admins, pre-moderation, etc., which can take months, if not years, for a webmaster, especially a beginner, to implement.
  • The user does not need to register, enter his name, etc. - it is assumed that he already has an account on a popular social network.
  • Most likely, it will withstand a heavy load due to the fact that social. platforms are initially designed for heavy loads.

Flaws:

  • Poor or complete lack of ability to change the appearance of the block with comments.
  • Indexing in search engines.

As you can see, there are many more benefits. The inability to change the appearance is most likely done in order to recognize the style of the comment service, thus creating unobtrusive advertising. (As one of the options). As for indexing, is it really that important, because not all comments carry meaning.

But enough theory, let's move on to practice.

1. The simplest option- add comments using a selected social network.

For example, vk. Let's look at the documentation. We copy the provided code and add it to the page (pieces of code were taken from the docs at the link, they may change in the future, so always copy from the documentation site. Here is only a possible example):

1) Add to:

VK.init((apiId: 2951023, onlyWidgets: true));

2) Add in the place where we want to see the comments widget (for example, after a note, if we are talking about a blog):

VK.Widgets.Comments("vk_comments", (redesign: 1, limit: 10, width: "665", attach: "*"));

2. Add widgets from several services. For example, like on this resource. Switch tabs:


Add to the markup (for correct operation it must be connected twitter bootstrap!) in the place where you want to display the comment widget:

But this option is not the best, although it is the simplest. The problem is that with this approach, all widgets will be initialized when the page is loaded, regardless of whether the user needs them or not.

This can be avoided by implementing lazy initialization of comment widgets. First the entire code, then an explanation:

(function(global, $) ( "use strict"; $(function() ( var $tabToggler, initComments, initialized; initialized = ( "#vk-comments": false, "#disqus_thread": false ); initComments = function (type) ( var discussUserName, disqus_config, pageUrl; if (initialized) ( return; ) pageUrl = "page_url"; switch (type) ( case "#disqus_thread": // You need to set this params using your platform"s appropriate way discussUserName = "discussUserName"; disqus_config = function() ( this.page.url = pageUrl; return this.page.identifier = "page_identifier"; ); (function() ( var d, s; ​​d = document; s = d.createElement("script"); s.src = "//" + discussUserName + ".disqus.com/embed.js"; s.setAttribute("data-timestamp", +new Date()); d.head || d.body).appendChild(s); break; case "#vk-comments": VK.Widgets.Comments("vk-comments", ( limit: 5, attach: " *", pageUrl: pageUrl )); break; default: return; ) initialized = true; ); $tabToggler = $(".comments-wrapper a"); $tabToggler.on("shown.bs.tab", function(e) ( initComments($(e.target).attr("href")); )); initComments($tabToggler.closest(".active").find("a").attr("href")); )); ))(window, jQuery);

Pay attention to the variables whose value you must prepare using the methods provided by your platform.

First, let's create a mapping of comment widget types, a variable initialized. Next, function initComments(type) allows you to initialize a comment widget, and it does nothing if it has already been initialized.

AND finishing touch- initialize the default comment widget so that it appears immediately after the page loads.

Ready script for and coffeescript for gist. An example of work is below (code examples taken from this site)

(in which we removed h3 tags in the header before the comment form) - today we will make the WP comment form function work entirely according to our rules:

We will have the opportunity to set our own styles, change the “Add comment” title at our discretion, exclude, if necessary, certain information entry windows, for example, the url form, customize the placeholder, etc. and, most importantly, do not lose all this when updating the engine.

Now we can easily achieve our goal, just by editing the function file. And if you feel strong enough to edit the site code (this method is a little more complicated than the one described earlier)…

Let's start the concert:

Is it worth editing WordPress core?

As you know, editing the WordPress core (CMS files) is not a recommended activity, largely due to the fact that after updating the engine, work is lost! Moreover, for novice resource administrators, these WordPress updates are made suddenly (without their knowledge). How to avoid this, read this.

Is it worth upgrading WordPress?

Absolutely yes! …there can be no disagreement here! ...however, this is fraught, as was said, with the fact that the engine update will overwrite the administrator's editions!

Therefore, many web masters, for more flexible settings their site, use all sorts of filters (hacks): not bad either! However, I (and not only me) prefer to move some minor (relative to the importance of constant updates) functions of the WP core to the root of the template.

Thus, output the necessary adjustments to the theme files in order to manage the state of the site at the template level: without any losses)

Let's start editing, but!!

...I remind you every time: create some kind of document “memory” of all the incidents committed with the blog. Copy edited files. It will come in handy!

Believe me: this is short of professionalism, because the possibility of digesting accumulated grains of knowledge into mush is unlikely!

What we need to achieve the goal:

transfer the processing of the comment_form function from the WP core (from the comment-template.php file) to the template directory.

where to find the comment-template.php file

Follow this path your_domain/wp-includes file comment-template.php

...open it (or directly on the hosting - that’s what I do), or download and edit it in Notepad++ - read: how to set up Notepad++

Look for a line like this (approximate line number 2111)

function comment_form($args = array(), $post_id = null) (

do_action("comment_form_comments_closed");

You copy all this and transfer it to your functions file functions.php.

Typically, all new code additions are placed before the closing ?> tag. But I recommend grouping the added code, so to speak, by topic, then you can easily find everything if necessary.

The next step is to change the name of the function: you can call it whatever you want, even designate it with a personal monogram... I did it like this:

function my_my_ comment_form

We save our achievements...

...and go to your theme's comments.php file.

In this file we need to change the name of the function call to the one we called in the first step:

You look for the following phrase in the document (it’s usually at the end): and simply add my_my_ or your name.

It should look like this:

…now the challenge is new feature done: the template logic will use our code copied into the theme!

Just what we needed!

Now all you have to do is edit the code of the newly created function my_my_comment_form();

...or set up an individual placeholder - look at what it looks like for me:

...in my comment form window there is a monogram “Your comment...” which disappears as soon as the commentator types his message...

...and so on...and so on...like that.

If you have any questions about adding/removing elements of the comment form, write and we’ll sort it out...

or here you can read a post about useful snippets (

It's time to get serious about decorating appearance WordPress comments. In almost all themes, they are configured by system files, which in turn limits editing of individual functions. I think many people have encountered this when they needed to make changes to comments, but could not find where exactly it was. Therefore, it would be better to transfer all the functionality to the current theme, which will give us complete freedom of control.

In this article I have collected several interesting features, which will help improve comments. Still, they allow you to conduct dialogues both with the site administrator and between users. Answer questions, start various discussions, in general, introduce full-fledged virtual communication. So it is necessary to pay attention to them and bring them into proper shape.

Here's what we'll do:

  • Full customization
  • Appearance design
  • Numbering of comments
  • Counting messages per user
  • Assign a status to each user
  • And other little things

We will analyze each item separately, and at the end of the article all functions will be completely collected into one ready code.

Customizing Comments

In WordPress, comments are displayed through the wp_list_comments function, usually in the comments.php file. And the formation of individual functions, as well as the cycle itself, is used from the template system file comment-template.php . But in rare cases it happens that the setting may be in WordPress theme, functions.php or comments.php file.

So, if your theme does not fall into a rare case and you need to make your own settings, then open the functions.php file and before the ?> sign add the following code:

If (! function_exists("my_comment")) : function my_comments($comment, $args, $depth) ( global $commentnumber; $GLOBALS["comment"] = $comment; switch ($comment->comment_type) : case " pingback" : case "trackback" : ?>

  • After these manipulations, your comments will be generated using a template function from the functions.php file of the current theme.

    Counting comments for each user

    Using the function presented below, we can display the total number of messages left next to the commentator. Thus, it is possible to observe how active user, and besides, statistics are never superfluous, especially in this regard.

    We open the functions.php file we are already familiar with and add the following code at the end before the ?> sign:

    //counting user messages function bac_comment_count_per_user() ( global $wpdb; $comment_count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM ". $wpdb->comments." WHERE comment_author_email = "" . get_comment_author_email() ." " AND comment_approved = "1" AND comment_type NOT IN ("pingback", "trackback")"); if ($comment_count == 1) ( echo " 1 Message"; ) else ( echo " " . $comment_count . " Messages "; ) )

    Now all that remains is to add the call function to the location you need:

    Messages will be counted based on the user's e-mail, whether registered or not. Only comments confirmed by the site administrator are taken into account, but those in standby mode and deleted are not.

    We assign a status to each user depending on the number of comments

    This is precisely the case where statistics definitely play an important role. Since the function is built on the basis of the number of messages, and the resulting number gives the user the proper status. This, in theory, is used on every forum to show the authority of the user on a given resource.

    Open the functions.php file again and before the ?> sign add the following code:

    //user status function get_author_class($comment_author_email,$user_id)( global $wpdb; $adminEmail = get_option("admin_email"); $author_count = count($wpdb->get_results("SELECT comment_ID as author_count FROM $wpdb->AdminUseR "; if($author_count>=1 && $author_count=50 && $author_count=100 && $author_count=250 && $author_count=400 &&$author_count=800 && $author_countProfessor"; )

    And in the desired place we display the calling function:

    Explanation: the function, like the previous one, is associated with the user’s email. Only here the main task is not just counting messages, but the number from and to depending on the set number. And once the user reaches it he gets a certain position. There are 7 statuses in total, plus admin and insignia for registered participants.

    Completely finished comment code

    Here we come to the end of this article. Here I was not lazy, collecting all the functions, including setting up comments, into one ready-made code. I added my own styling styles and the result was something like a mini-forum.

    Open the functions.php file and at the end before the ?> sign add the following code:

    //counting user messages function bac_comment_count_per_user() ( global $wpdb; $comment_count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM ". $wpdb->comments." WHERE comment_author_email = "" . get_comment_author_email() ." " AND comment_approved = "1" AND comment_type NOT IN ("pingback", "trackback")"); if ($comment_count == 1) ( echo " 1 Message"; ) else ( echo " " . $comment_count . " Messages "; ) ) //user status function get_author_class($comment_author_email,$user_id)( global $wpdb; $adminEmail = get_option("admin_email"); $author_count = count($wpdb->get_results("SELECT comment_ID as author_count FROM $ wpdb->comments WHERE comment_author_email = "$comment_author_email" ")); if($comment_author_email ==$adminEmail) echo "Admin"; if($user_id!=0 && $comment_author_email !=$adminEmail) echo "UseR"; if ($author_count>=1 && $author_count=50 && $author_count=100 && $author_count=250 && $author_count=400 &&$author_count=800 && $author_count=1200 && $comment_author_email !==$adminEmail) echo "Professor"; ) //customize comments if (! function_exists("wordsmall_comment")) : function wordsmall_comment($comment, $args, $depth) ( global $commentnumber; $GLOBALS["comment"] = $comment; switch ($comment- >comment_type) : case "pingback" : case "trackback" : ?> @ Reply to:

    Change to this:

    The final step. Open the style.css file and at the end add the following styles:

    My_commentlist( border-top:none; ) .my_commentlist .comment( padding:0 0 15px 0; border:none; ) .my_commentlist .pingback( padding:0 0 15px 0; border:none; ) .my_commentlist .comment .children ( list-style-type: none; padding:0px; margin-left:0px;/*if you need a margin for tree-shaped coms, put 15px*/ .my_commentlist .comment .children .comment( margin:15px 0 0 0; border: none; padding: 0; ) #comments ( background: #fff; ) #comments .my_commentlist ( margin: 10px 0; padding: 0; list-style: none; background: #ebf0f3; padding: 5px; ) #comments .my_commentlist .comment ( margin:0; padding: 0 0 10px; background: #fff; ) #comments .my_commentlist .my_comment-author ( display: inline; border-right: 1px solid #e0e0e0; width: 100px; float: left; margin : 0px 15px 10px 0; ) #comments .my_commentlist .commentmetadata ( float:left; ) #comments .my_commentlist p ( clear:none; color: #555; font: 14px arial; line-height: 23px; ) #comments .my_commentlist .comment-content ( margin-left: 116px; padding-right: 10px; ) #comments .my_commentlist .reply ( text-align:right; ) #comments .my_commentlist .reply a( background: #f5f5f5; border: 1px solid rgba(0, 0, 0, 0.06); border-radius: 2px; color : #515456; font-size: 13px; line-height: 30px; min-height: 0 12px; ; text-decoration: none; ) .my_commentlist .avatar( border: medium none; border-radius: 50%; float: none; margin: 5px auto; padding: 0px; display: table; ) .my_commentlist .comment-header( height: 30px; background: #DEE5EB; margin-bottom: 15px; ) .my_commentlist cite.fn( color: #444; font: bold 13px/30px arial; padding-left: 10px; ) .my_commentlist .com_date ( color: # 8ca0b5; font: normal 13px/30px arial; float: right; padding-right: 15px; ) .my_commentlist .comment-body ( overflow: hidden; position: relative; background:#fff; ) .my_commentlist .rep-authorcom ( color: #25394e; font-size: 13px; line-height: 30px; ) .my_commentlist .edit-link a ( background: none !important; border: none !important; border-radius: 0 !important; color: #999!important; font-size: 11px !important; line-height: 30px; min-height: 30px ; padding: 0 !important; text-align: none; .com_per ( border: medium none; color: #666; display: block; font-size: 11px; text-align: center; ) .vip1,.vip, .vp, .vip2, .vip3, .vip4, .vip5, .vip6, .vip7 ( border: medium none; font: bold 13px arial; display: block; text-align: center; margin- bottom: 5px; text-decoration: none; ) .vp (color: #e82e24;) .vip1 (color: #348be8;) .vip2 (color: #BE005E;). color: #658a18;).vip5 (color: #00A56D;).vip6 (color: #e35d28;).vip7 (color: #99A400;).vip (color: #4c5176;font-size: 11px;margin: 0 ;)

    The code is fully working and does not cause errors, but minor changes to the CSS styles may be needed.

    Recently one of our readers asked if it was possible to allow anonymous commenting in WordPress. By default, users cannot leave comments in WordPress without providing a name and address. Email in the form of comments. In this article, we will show you how to allow users to leave comments anonymously in WordPress. We'll also show you how to hide the name and email fields from the comment form.

    Nickname: Ideal Solution

    Most The best way Allow anonymous comments in WordPress - Encourage users to use pseudonyms or nicknames instead of their real name.

    This will allow you to build a community, while at the same time allowing users to remain anonymous. Commenters will still have to leave their email address, but most people who wish to remain anonymous will use an additional email address.

    You can specify such options in the comment policy and provide a cross-link to them above the comment form.

    While this solution is ideal and the only one we recommend, there are other solutions for author anonymity. But remember, the more anonymity a site has, the more spam it will contain.

    Making the Name and Email fields optional

    The next layer of anonymity you can add is to make the Name and Email fields completely optional. If the user only submits a comment, without a name or email, it will pass. Let's look at how to make the Name and Email fields optional.

    First of all, you need to go to the Settings » Discussion section of the site’s administrative panel and uncheck the “Comment author must provide a name and e-mail.” Now you need to save the changes and your site will accept comments without name and email.

    Simply removing this checkbox will not inform users that they can now leave comments without providing a name or email. You can notify them of this by marking the corresponding fields as optional. We also recommend removing the Website field to reduce the amount of spam. To do this, you need to modify your comment form. Simply copy and paste the following code into your theme's functions.php file or :

    Function wpb_alter_comment_form_fields($fields) ( // Modify the Name field and display it as optional $fields["author"] = "

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

    "; // Modify the Email field and display it as optional $fields["email"] = " "; // This line removes the Website field from the comment form. $fields["url"] = ""; return $fields; ) add_filter("comment_form_default_fields", "wpb_alter_comment_form_fields");

    This code simply adds (Not necessary) to the Name and Email fields in your comment form. It also removes the Site field from it. If you want to leave the “Site”, then simply delete the corresponding lines of code. This is what your comment form will look like:

    How to completely remove the Name and Email fields from the comment form

    For those users who want to completely remove the Name and Email fields from the comment form, here is a small piece of code to paste into your theme's functions.php file or :

    Function wpb_alter_comment_form_fields($fields) ( unset($fields["author"]); unset($fields["email"]); unset($fields["url"]); return $fields; ) add_filter("comment_form_default_fields" , "wpb_alter_comment_form_fields");

    If your form displays text Your email address will not be published(Your email will not be published), then you can hide it by editing the theme's comments.php file. Find the tag and replace it with the following code:

    If you can't find the comment_form , you can simply hide this text by adding the following CSS code to your theme or a child theme's style.css file:

    Comment-notes ( display:none; )

    This is what your comment form will look like without the name, email and website fields:

    Warning about anonymous comments

    Please note that without the required email fields, your form will attract a lot of spam. Even though Akismet and Sucuri can block some bad IPs, we highly recommend adding a captcha to reduce spam.

    We hope this article helped you allow users to comment anonymously in WordPress. We've shown a lot of styles for comment forms, so if you want to learn more about this topic, check out our article