Allow users to post anonymous comments in WordPress. Commenting WordPress Publish add comment p

Whether you need to comment on a WordPress site or not is up to the site owner. The WordPress system was originally designed with flexible management and organization of comments. Comment settings, and on WordPress they are called "Discussion Settings", are some of the most, if not the most voluminous.

In this article, I will not argue whether you need comments on WordPress or not, it is up to you, here we will see how to manage commenting on a WordPress blog (site) using the system features and functionality of phpmyadmin, as well as third-party plugins.

How to enable and disable general commenting in WordPress

WordPress comment management is located under the "Settings-Discussion" tab. The "Settings-Discussion" tab is one of the most voluminous in the system. Here you can:

  • Enable or disable commenting for the entire WordPress blog, including all posts, pages, media files;
  • Set the period for commenting on new articles (by default, 14 days);
  • Specify the nesting level (tree) of comments;
  • Enable backlink management in comments;
  • Determine the order of comment moderation and 5 more groups of settings.
Setting up WordPress commenting

How to disable commenting on individual posts and pages in WordPress

Management, or rather a button to deny / allow comments is on the pages of the editor of posts and pages. To make it appear on the screen, open the "Settings" slider at the top and tick the "Discussion" checkbox. Now, you can turn off commenting for an individual article and page.

How to remove all WordPress comments

There are two ways to delete all WordPress comments:

1. From the control panel on the "Comments" tab. It is enough to select the checkboxes of the deleted comments or select all comments and select "Action-Delete".
commenting WordPress

1. From the phpmyadmin panel. Log in to your hosting panel and log into phpmyadmin. Open your WordPress database and find the "wp_comments" table. This is where your blog comments "lie". If you need to delete all comments, click on the "Clear" button in the "wp_comments" line. The table will be cleared, which means that all comments on the blog will be deleted.

How to remove comments from individual WordPress users

Removing comments of individual users (subscribers) is done in the same way as in the previous paragraph, only by filtering users by name (email, ID).

Option 1. In the control panel go to the "Comments" tab. In the filter, enter the user you are looking for, whose comments you want to delete. Select the checkboxes of these comments and delete.


Comment control buttons

Option 2... Go to phpmyadmin. Open your blog database.

Note: Before working with the database, make a backup copy of the database, the "Export" button.

You can make a SQL query and show how smart you are. But we came to phpmyadmin, and this is an interface for simplifying the work of the database. Therefore, let's go the simple way:

  • Let's open a table with comments;
  • In the "Sort by Index" field, sort the table by the field you need. For example, by email of the user (comment_author_email);
  • Now insert the email of the desired author into the filter and press "Enter";
  • We see all the comments of this author and, having selected their checkboxes, delete them with the "Delete" button.

Back to SQL queries. All actions with filters can be replaced with the following SQL queries to the database (in requests wp change your database to a prefix):

Delete comments by user ID:

DELETE FROM `wp_comments` WHERE` wp_comments`.`comment_ID` = 2

// 2 is the value of the user ID, multiple users can be separated by commas.

Delete comments by email author:

DELETE FROM `wp_comments` WHERE` wp_comments`.`comment_author_email` = "author's email"

Removing comments by his name:

DELETE FROM `wp_comments` WHERE` wp_comments`.`comment_author` = "Author_name"

Continuing the topic of SQL queries for WordPress, read the article "", I supplemented it with a few more useful queries. Better yet, learn the materiel, SQL queries for WP, it's very easy to compose yourself.

Plugins that extend the functionality of commenting

Here are two plugins that will take commenting to the next level.

The first plugin is the "Discus" plugin (https://wordpress.org/plugins/disqus-comment-system/). It syncs your WordPress blog with the Discus comment service (https://disqus.com/home/explore/). Comments left by your users or guests will settle online under their address: your_discus.discus.com and can live their lives online, improving site optimization by participating in Discus community condemnations or opening your own channel.

The second plugin is called "Comments - wpDiscuz" (https://wordpress.org/plugins/wpdiscuz/). AJAX real-time commenting system with custom comment form and custom fields. Designed for WordPress system comments add-on. Very fast and responsive with dozens of features.

There are several types of content in WordPress such as posts, pages, comments. WordPress is a very flexible platform that allows you to customize the main types of 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 function comment_form and its arguments

Consider the WordPress function comment_form. She is responsible for displaying the comment form, which is displayed on a page or post. The call to this function can mainly be found in the file comments.php in the theme folder. This file is included in various places, for example, in files single.php and page.php, directly or through a call to the comments_template function.

The function description can be found in the WordPress codex.

If you use the comment_form function to render the 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 - it can be used to control the display of fields in the comment form.
  • comment_notes_before and comment_notes_after are used to display information before and after the form.
  • title_reply - used to change the title of the reply, which is ‘Leave a Reply’ by default.
  • label_submit - used to change the text on the submit button.

Step 2. Customize the comment form using the function comment_form

Now let's customize 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 their list to the comment_form function. By default, the function uses the following list of fields:

$ fields = array ("author" => "

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

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

" . "

",);

If we need to remove a field, for example website, we just 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" => "

" . "". ($ 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 caption on the button to ‘Send My Comment’.

To complete the task, 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" => "

" . "". ($ 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 WordPress comment form can be changed 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 given code can be used in a plugin or in a file functions.php active topic.

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 the hook

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

Add the field as follows:

Function add_comment_fields ($ fields) ($ fields ["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 at '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 has been saved, it can be displayed in a comment as follows:

comment_ID, "age", true); ?>

Step 5. Customizing Comments for Specific Post Types

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

Function add_comment_fields ($ fields) (if (is_singular ("books")) ($ fields ["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 in posts. The WordPress codex describes the function in detail.

wp_list_comments has a ‘callback’ argument in which you can define a function to be called when a comment is displayed.

In Twenty Eleven theme in file comments.php 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 every record.

Step 7. Styling comments

We will now change the style of the comment a little. We will simply display the content of the record and the age field that we added earlier. We will also change the background color for the comments.

Function code 'my_comments_callback':

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

  • id = "li-comment-">

    comment_ID, "age", true); ?>

    __ ("Reply ↓", "twentyeleven"), "depth" => $ depth, "max_depth" => $ args ["max_depth"]))); ?>
  • Change the background color as follows:

    Commentlist> li.comment (background: # 99ccff; border: 3px solid #ddd; -moz-border-radius: 3px; border-radius: 3px; margin: 0 0 1.625em; padding: 1.625em; position: relative;)

    Honestly, when I saw what they write about this and advise newbies on other sites, I was a little horrified and decided to write down my note on this topic without a fatal flaw. Basically I've seen long pieces of code that implement adding comments to the site... Usually, for this, a form is created, its processing, saving, as well as selections for display are implemented. But the advantages of such an approach become less and less.

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

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

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

    Benefits of third-party solutions:

    • Ease of implementation.
    • Protection against spam "out of the box" (in my decision I would have to implement this additionally, so, in theory, 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 the popular social network.
    • Most likely, it will withstand a heavy load due to the fact that social. platforms were originally designed for heavy loads.

    Disadvantages:

    • Poor or complete lack of the ability to change the appearance of the block with comments.
    • Search engine indexing.

    As you can see, there are many more advantages. The inability to change the appearance is most likely done in order to recognize the style of the comment service, thus creating an unobtrusive advertisement. (As one of the options). And as for indexing - is it really that important, because not all comments carry a semantic load.

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

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

    For example, vk. We look at the documentation. We copy the provided code and add it on the page (pieces of code are taken from the docks by the link, may change in the future, so always copy from the site with the documentation. Here is only a possible example):

    1) Add to :

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

    2. Add widgets from multiple services. For example, as on this resource. Switched by tabs:


    Add to the markup (twitter bootstrap must be connected to work correctly!) In the place where you want to output comment widget:

    But this option is not the best, albeit the simplest one. The problem is that with this approach, all widgets will be initialized on page load, regardless of whether the user needs them or not.

    This can be avoided by implementing lazy initialization of comment widgets... First, the whole 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 ()); return ( 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, the value of which you must prepare using the methods provided by your platform.

    First, we create type mapping comment widgets, variable initialized... Next, the function initComments (type) allows initialize comment widget and it does nothing if it has already been initialized.

    And the final touch - we initialize the default comment widget so that it will be displayed immediately after the page is loaded.

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

    Hello friends and blog guests! Today I'll tell you using PHP and MySQL. And also we will talk about commenting systems for the site and choose the best one for your site from those offered by me.

    The first question: by using PHP and MySQL?

    To do this, you and I need to first create a table in the database of your site, which will be called - comments... This created table will store comments in fields with the following designations:

    id Is a unique identifier.
    page_id- this field will store the identifier of the site page on which this comment is located.
    name Is the name of the commentator who left the comment.
    text_comment- respectively, this is the text of the current comment.

    The next step, after creating a table for comments in the database, we need to inject special code for our future comments on the site. This code on the site will allow our commenters to add their comments to our articles. Here's the code:


    This is a simple HTML comment form for a website. You place it on your site in the place where it is convenient for leaving a comment on the post - of course, under the post itself.

    query ("INSERT INTO` comments` (`name`,` page_id`, `text_comment`) VALUES (" $ name "," $ page_id "," $ text_comment ")"); // Add a comment to the table header (" Location: ". $ _ SERVER [" HTTP_REFERER "]); // Do we redirect back?>

    The last step in creating a comment form for a site in PHP and MySQL is to display our comments on the site page. Here's the code for that:

    query ("SELECT * FROM` comments` WHERE `page_id` =" $ page_id ""); // Fetch all comments for this page while ($ row = $ result_set-> fetch_assoc ()) (print_r ($ row); // Output comments echo "
    "; } ?>

    That's all! Our simple site comment form has been created and can be run on the site.

    But this is certainly not for a beginner who will not dig with all this HTML, PHP and MySQL codes. Nor will he learn how to create a database. He needs everything at once, quickly and without headaches. I'm right? Of course right!

    Then let's move on to the next section of my material and find out everything about ready-made commenting systems for the site and choose the most convenient, functional and acceptable for your site ...

    Systems of comments for the site. Which one to choose?

    How to make comments on the site- this is an important question because comments on the site play an important role not only for communication between the site owner and the visitor, but also comments are important for SEO promotion and promotion.

    With the help of comments on the site, the position of the site in the search results increases, behavioral factors improve, traffic to the site grows, and, consequently, your earnings increase. You see how important comments are for the site!

    So let's consider how to make comments on the site and what commenting system to choose as the best option?

    In general, comments on sites are displayed in many ways. These are special plugins for wordpress engines and all kinds of comments from social networks, such as for example In contact with, Facebook, Disqus... There are also independent services that offer their own commenting systems for the site, for example.

    Now I will give you one plate that will immediately put everything in its place and questions will no longer arise about the choice of a comment system for the site:

    Everything here is clear and clearly visible which comment system is the best and several presented, which are most often used by webmasters on their resources. I think that explanations here are superfluous and the choice is only yours!

    I have already made a decision for myself and installed a comment system for my site from Cackle.

    By the way, if you have already decided to choose a system for your site, then here is a link for you, which gives 5% discount to purchase the commenting system from Cackle!

    And I have everything for today! Good luck and prosperity to everyone! Until next time!

    Hello dear readers, today I would like to talk with you on the topic commenting on articles... Many, especially young blogs, have an acute problem of post commenting. How do you get the reader to write comments?

    The author tries to write material, the readers do not react at all. The author has the impression that he is writing in a blank, and he ceases to like it. I have acquaintances who gave up their hobby on this occasion.

    Today I will reveal to you 8 secrets that will get your readers to write a comment on the. Of course, I said highly, these are not secrets, but facts that many forget and themselves suffer from this. But before using these methods, do not forget to protect yourself from ;-).

    How do I get a visitor to write a comment?

    Everything is simple, you just have to try a little to follow the rules I described below, after which the number of comments on your site will slowly begin to replenish. But this does not mean that you can stupidly use these chips and everything will be fine. You need to analyze what kind of visitors you have, what exactly they want and what to catch them on. You can do this with the help of or 😉 Let's start ...

    As a rule, readers do not comment out of fear: “What will they think of me? What if I write the wrong thing and everyone will laugh ... ". You, as the author of the site, must make it clear to the reader that you are the same person as everyone else, that there is nothing to be afraid of ...

    To do this, you just need to create a page "" and write to yourself how you started, where you studied, where you live, and so on. The "Personal" section also works well, where from time to time you will write articles about yourself, for example, when you find yourself in a funny situation, or.

    Also, plugins like this work very well - a plugin for displaying the last comments left. People will see that your site is actively commenting and nothing terrible happens 😉

    2) Encourage the reader to leave a comment.

    Constantly ask the reader about something, ask questions, ask for your opinion. Then the reader will feel that you are really interested in his comments and will not leave you unattended. Many bloggers use this method:

    They do not fully disclose the topic of the article, this is suitable for sites that write stories for the soul, but not for my topic. Therefore, I am against this method, it is better to write in detail and disassemble the topic of the article, and at the end, hint to the readers that you can tell a little more, then the discussion will go 😉

    3) Use contests and other nudges to comment.

    In the past, so-called comment contests have worked very, very well where readers benefit from their comments on the site. Now this method works less efficiently, all the fault is the other FAT contests, which are arranged by popular bloggers with the help of sponsors such as Rookee, Seopult and so on ...

    These contests have a budget of tens to hundreds of thousands of rubles, so a comment contest with a prize of 500 rubles will not surprise anyone. And this way you can only push those who love you and constantly read, but they lacked something to leave a comment. .

    Types of comment contests:

    The most popular competition is the number of comments () competition. A competition is launched, and the very-very commentator who wrote the most comments for a certain period of time is determined, and he is awarded an award, it is not uncommon for such contests to contain 3 prizes.

    In addition to this competition, such competitions are often held where, for example, the most informative comment is determined, or the best question posed to the author, for this you can use the rating system for the comment. The authors of these comments are happy, while others are waiting for a new similar competition to try again to get their penny

    4) Comments that create a dispute.

    Try to constantly express your opinion, even if it goes against the public. Very often, articles like why Android is better than iOs get record numbers of comments because people argue. One of my articles is where I wrote why it is better and slightly humiliated other CMS systems.

    I still get messages from people asking me to try other CMS, so that I feel that they are better than WordPress. At that time, despite the fact that the article was one of the very first, and the blog was only about a week old, the article really got a record number of comments, if my memory serves me right.

    5) Always reply to every comment.

    Do you not like it when you write an article and readers do not comment on it? Likewise, the author of the comment, who remained unanswered, is unlikely to write comments yet. There are only a few authors who will finish you off until you answer. Therefore, do not offend your readers ...

    If possible, thank the reader for the comment (you can for the first comment) and answer his question in as much detail as possible, agitate to ask more, promise that you are always ready to answer any comments, and keep your promise. Then the readers will feel that they are interested in them and will not leave you unattended….

    7) Comment on other blogs.

    It may sound ridiculous, but it still works. If you leave interesting comments on other sites, moreover, it can raise your authority, the authority of the site, and even bring new visitors to the site. There are several examples where, with the help of one comment, bloggers got themselves a mountain of new visitors ...

    But for this you need to write really strong, interesting and informative comments. They should hurt not only the readers of the blog on which you left comments, but also the author of this site. But if you succeed, consider that you have killed a big jackpot.

    8) Leave a comment with the same name and with the same avatar.

    It is very important! Whether it is if you leave comments on your site, or on someone else's, always do it only with the same nickname and avatar. I wrote here how to use the same avatar. Why do you need to do this?

    See you soon, your humble servant Albert and blog ...