Configuration
You can customise Comments’ settings using a PHP configuration file. This is optional: each setting has a default, so you only need to include the values you want to change.
To override a setting, create comments.php in your Craft project’s /config directory and return an array of setting names and values. For example, the following will let guests comment:
<?php
return [
'allowGuest' => true,
];All other settings keep their defaults. Add any further settings you want to change to the same array. The options below explain the available settings and their defaults. You can also manage many of these settings in the control panel under Comments → Settings.
Configuration Options
Sets a custom name for the plugin in the control panel.
General
Whether guests (visitors who aren’t signed in) can post comments.
The message shown to guests in place of the comment form when allowGuest is false.
Whether guests must enter their name and email to comment. Only applies to guest comments.
Whether guests are shown fields to enter their name and email. Only applies to guest comments.
Whether new comments need to be approved by a moderator before they’re publicly visible.
The UID of the user group whose members moderate comments. This group also receives moderator notifications, and its members can skip moderation with moderatorExcluded.
Whether comments from members of the moderatorUserGroup group skip moderation themselves.
Closes commenting on elements older than this number of days, based on the element’s Post Date. Leave it empty (null) or set it to 0 to never close commenting automatically.
The number of levels of replies comments can have. Use null for no limit, 0 to turn off replies, or any other number to limit how deeply replies can nest.
The number of comments each user can make on a single element. Use null for no limit.
The statuses comment queries return when you don’t set a status parameter yourself. Add pending or other statuses to show those comments by default.
Which elements can be commented on, keyed by element type. Each value is either '*' to allow commenting on every element of that type, or an array of UIDs for the “groups” of elements that allow commenting. Use section UIDs for entries (or entry type UIDs for entries without a section, such as nested entries), volume UIDs for assets, category group UIDs for categories and user group UIDs for users. Element types that aren’t listed allow commenting everywhere.
'permissions' => [
'craft\elements\Asset' => [
// Volume UIDs
'33974e79-b3b6-47ec-af91-4519fe4985be',
'c194716f-aa74-40b6-8426-c835599cbe93',
],
'craft\elements\Category' => [
// Category Group UIDs
'a27827c8-4810-433c-acb9-261b53d46281',
'346194f0-6da8-4f46-a20b-795631ee9a5f',
],
'craft\elements\Entry' => [
// Section UIDs
'a8d4bdf1-164e-4ddc-aaad-640026b8d3bf',
],
'craft\elements\User' => [
// User Group UIDs
'c23a4d8d-47f0-4e71-927c-d5897ec9c9f8',
],
],Voting
Whether signed-in users can upvote or downvote other users’ comments.
Whether guests can upvote or downvote comments.
The number of downvotes a comment needs before its isPoorlyRated property is true. You can then decide how to handle poorly rated comments in your templates.
Whether to hide the voting controls on a comment once it reaches the downvoteCommentLimit threshold.
Whether to show each registered user’s total score (the net votes across all their approved comments) next to their name.
Flagging
Whether signed-in users can flag a comment as inappropriate, spam or for any other reason.
Whether guests can flag comments.
The number of flags a comment needs before its isFlagged property is true. You can then decide how to handle flagged comments.
Comment Form
Whether custom fields in the comment form show their field names as labels.
Whether custom fields in the comment form show their instructions underneath their labels.
Whether commenters can search GIPHY and attach a GIF to their comment or reply. This also needs a giphyApiKey.
Your GIPHY API key, used for GIF search. It stays on the server and is never shown to visitors. This setting supports environment variables.
The highest GIPHY content rating to include in search results. Use g, pg, pg-13 or r.
The maximum number of GIFs shown for each search.
Default Templates
Whether to show an avatar for each comment. Users who comment have their user photo shown, while guests are shown the placeholderAvatar.
The asset shown as the avatar for guests when showAvatar is enabled, set as an array holding the asset’s ID, such as [123]. Because asset IDs differ between environments, this is usually easier to set in the control panel.
Whether to show a commenter’s Gravatar, based on their email. If they don’t have one, their user photo or the placeholder avatar is used instead.
Whether to show how long ago each comment was made.
The order comments are shown in on the front end. Use desc for newest first or asc for oldest first.
Whether to output the default CSS for the comment form.
Whether to output the default JavaScript for the comment form.
Serves the default CSS and JavaScript from this base URL, such as a CDN or file server, instead of publishing them to cpresources. You’re responsible for deploying the plugin’s resources/dist files to this location, which assetBasePath can help with. This setting supports environment variables.
The filesystem path the plugin’s resources/dist CSS and JavaScript are copied to when publishing. It should map to the location assetBaseUrl serves. Comments copies the files on install, from the button on the settings screen and with the comments/base/publish-assets console command. This setting supports environment variables.
Custom Templates
A folder in your site’s templates directory containing your own versions of the Comments templates. Any template Comments finds there is used instead of its default.
The site template Comments uses for HTML emails. When it isn’t set, Comments uses Craft’s default email template.
Security
Whether to run spam checks on comments submitted through the front-end form, including the hidden form checks and reCAPTCHA. When this is disabled, comments that fail those checks are still accepted.
The maximum number of characters a single comment can have.
The minimum number of seconds a commenter must wait between comments, to prevent comment flooding.
Words or IP addresses, one per line, that mark a comment as pending when they appear in its content, name, email or IP address. Matching is case-insensitive.
Words or IP addresses, one per line, that mark a comment as spam when they appear in its content, name, email or IP address. Matching is case-insensitive.
Words or IP addresses, one per line, that stop a comment from being submitted when they appear in its content, name, email or IP address. Matching is case-insensitive.
Whether keywords only match whole words. When this is enabled, ‘craft’ no longer matches ‘crafty’.
Whether to use reCAPTCHA to protect the comment form against spam. This also needs a recaptchaKey and recaptchaSecret.
Your reCAPTCHA site key. This setting supports environment variables.
Your reCAPTCHA secret key. This setting supports environment variables.
The minimum reCAPTCHA score a comment needs to pass the check. Comments that score lower are rejected as spam.
Notifications
Whether to send notification emails through Craft’s queue. This is recommended, because it stops sending emails from slowing down comment submission.
Whether the author of an element receives an email for every new comment on it.
Whether comment authors receive an email when someone replies to their comment.
Whether users are automatically subscribed to an element after they comment on it, so they’re notified of any later comment on that element.
Whether users are automatically subscribed to their own comments, so they’re notified when someone replies to them.
Whether signed-in users can subscribe to all comments on an element. This shows a Subscribe button at the top of the comments thread.
Whether signed-in users can subscribe to a specific comment thread. This shows a Subscribe button on each comment.
Whether members of the moderatorUserGroup group receive an email when a new comment needs moderation. When this is enabled, element authors aren’t notified until the comment is approved.
Whether moderators receive an email when a user edits their own comment and it needs moderation again.
Whether comment authors receive an email when a moderator approves their comment.
The administrators who receive the admin and flagged comment notifications. Provide an array of email addresses, each with an enabled item. Only enabled addresses receive emails.
'notificationAdmins' => [
[
'email' => '[email protected]',
'enabled' => true,
],
[
'email' => '[email protected]',
'enabled' => true,
],
],You can also provide a closure that returns this array, which is useful when the list comes from elsewhere in your project.
Whether the notificationAdmins addresses receive an email whenever someone comments on an element.
Whether the notificationAdmins addresses receive an email whenever someone flags a comment.
Comments Index
The default sort attribute for the comments index in the control panel, such as structure, commentDate or voteCount. It doesn’t affect the front end.
The default sort direction for the comments index in the control panel, either asc or desc. It doesn’t affect the front end.