Is it possible to override single plugin translation in function.php file and how that can be done?

  • Would you add the example code containing the string that you're trying to translate? This does sound doable. – Dave Romsey Mar 3 at 20:42
  • Haven't any code, just asking if it is possible. – Roger Wayne Mar 3 at 21:22
  • Okay, I've posted an example of a typical scenario. – Dave Romsey Mar 3 at 21:25

Here's an example where a string from a certain text domain is translated using the gettext filter:

/**
 * Translate a certain string from a particular text domain.
 *
 * @param string $translation  Translated text.
 * @param string $text         Text to translate.
 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
 *
 * @return string
 */
add_filter( 'gettext', 'wpse_translate_string', 10, 3 );
function wpse_translate_string( $translation, $text, $domain ) {
    if ( 'plugin_text_domain' === $domain ) {
        if ( 'Original string...' === $text ) {
            $translation = 'New string!';
        }
    }

    return $translation;
}

You can even override single messages if you go directly to your source code.

function foo(){
    // old message is commented, so you can go back anytime.
    //echo wp_send_json(array('status' => 'error', 'error_message' => esc_html__('Error Message', 'osetin')));
    // message is overriden 
    echo wp_send_json(array('status' => 'error', 'error_message' => esc_html__('Overriden message with any text you want', 'osetin')));
}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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