0

Got the way to change the labels everywhere for the post_type "Post". For a customer site, I need to use the WordPress comments. Just need to change the label from "Comments/Comment" to "Review" everywhere. But where for post_type "Post" we can use $wp_post_types;, what can we use for comments?

I tried with $wp_comments, $wp_comment etc. but failed.

How can I do it?

PS: I don't want a way to translate all the strings etc. Just need a way like the link pasted above. And not just the menu labels, I need to change them everywhere, so that under the post writing page, in the checkbox saying "All comments" would also change.

3

You can try the gettext filter.

According to the Codex:

This filter hook is applied to the translated text by the internationalization functions (__(), _e(), _x(), etc.). This filter is always applied even if internationalization is not in effect, and if the text domain has not been loaded.

Here's an example:

function custom_gettext( $translated_text, $untranslated_text, $domain )
{       
    if( FALSE !== stripos( $untranslated_text, 'comment' ) )
    {
            $translated_text = str_ireplace( 'Comment', 'Review', $untranslated_text ) ;
    }
    return $translated_text;
}

is_admin() && add_filter( 'gettext', 'custom_gettext', 99, 3 );

to change the strings containing Comment to Review (ignoring case).

You can adjust the replacements to your needs.

  • 1
    yes, but with this kind of search&replace over many strings it is hard to be sure that the end result always makes sense. For example something like "Liked our theme? please post a positive comment on themeforest" will become "Liked our theme? please post a positive review on themeforest" which might be ok but might not. – Mark Kaplun Dec 25 '13 at 10:37
  • yes this is the drawback when having this kind of restriction: I don't want a way to translate all the strings etc., so he will have to adjust the replacements to to his needs ;-) – birgire Dec 25 '13 at 10:48
  • @birgire is there any way I can hook with the gettext only in admin? It'll then solve the problem for me, Mark pointed here? – Mayeenul Islam Dec 26 '13 at 14:35
  • @birgire And also, it's just replacing the "Comment" on the admin menu to "Review", not everywhere, as I's searching. :( – Mayeenul Islam Dec 26 '13 at 15:49
  • @MayeenulIslam, I updated the answer so this should only work for the backend. Where did you spot the untranslated Comment text in the backend? – birgire Dec 26 '13 at 18:27
2

A more brute simple hack method is to use jQuery to find target string Comment and replace it with Review. To do this you can check out this thread:

https://stackoverflow.com/questions/8146648/jquery-find-text-and-replace

Example:

$("#container p:contains('Comment')").text("Review");

To include this script in your WordPress headers you can add an action and function in your theme's functions.php. For more details, check out:

http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head http://codex.wordpress.org/Function_Reference/wp_enqueue_script

0

The only way to change all the places with the word "comment/s" to "review/s" is by creating a new translation file for the core, relevant plugins (akismet) and the theme. There are just too many of them to handle in any other way.

The difference between comments and posts is that you can't register new comment types (no api for that) and that is the reason there is no simple way to handle the removal of comments in the same way as posts were removed in the question you pointed to.

  • I'm afraid Mark, my Question was against any "translation" way, because I already implemented it by this way. So it's a bad answer, I'm afraid. :( – Mayeenul Islam Dec 26 '13 at 15:34
  • @MayeenulIslam, na, every correct and on subject answer is good. It might not be useful for you but someone else might find it useful. – Mark Kaplun Dec 26 '13 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.