Automatically separate the user comments by the language they viewed the article in.
This plugin separates the user comments by the language they viewed the article in – this way you avoid duplicate content(which is frowned-upon from search engines) and comments in other languages than the one the current visitor is using(which is generally bad user experience).
You can manually change the language of each comment(and you will have to set it in the begining).
Bulk-editing of the comments language is also available.
The plugin is using comment-meta to specify the language for each comment, so nothing will break if the plugin is deactivated.
It also should work out-of-the-box for all themes that use the comments_template() function to render their comments.
The plugin also fixes an issue of qTranslate. The issue consists in the fact that whenever a user posts a comment(while viewing a post in a language different than the default one), he is redirected back to the post but in the default language and not the language he was reading the post before posting the comment.
/wp-content/plugins/
directory./wp-content/plugins/qtranslate-separate-comments
directory now with qtranslate-separate-comments.php
in it./wp-content/plugins/
directory./wp-content/plugins/qtranslate-separate-comments
directory now with qtranslate-separate-comments.php
in it.You have to associate each comment with a specific language. To do this, go to the Comments section in WordPress Dashboard and set the appropriate language for all of your comments(you can use the “Bulk Set Language” button after selecting some comments and the right language for them).
In order to properly identify where the comment is coming from, this plugin adds a hidden input to the Comments form. This is done by hooking a function to the comment_form
action hook, which is called from the comment_form()
WordPress function. If you are using a custom comments form instead of calling this function, make sure to add <?php do_action( 'comment_form', $post->ID ); ?>
. If this still doesn’t work, replace that code with the following: <?php global $post; do_action( 'comment_form', $post->ID ); ?>
.
Tested with WordPress 4.8 – still works! Also added support for qTranslate-X, as it seems to be an active fork of qTranslate.
Tested with WordPress 3.9 and everything works fine. Note that the current version of qTranslate(2.5.39) however breaks my test site with a fatal error.
Changed the tested up to version to 3.5.1. Changed stable tag from trunk to tag number.
Changed the passing of the comment language to a much, much more simple way, that should be more proof to errors.
Fixed a bug related to proper setting of the language/redirecting back. The code was tested both from a root-level install and a sub-directory install.
fix_comments_count()
function(a typo was returning the wrong comments count) – thanks @hyOzd