Aleš Sýkora wrote

Translate WordPress string with code

21. 1. 2021 in

Sometimes you want to change just one word in translation and you dont want to create .po and .mo files, install translation plugins etc.

So use the function str_replace and replace the string you want. For example I am changin “Add to cart” to “Přidat do košíku”.

You can place this code to your code snippets, custom funcionality plugin, functions.php… It is up to you :-).

function twiki_translate_string( $translated_text, $text, $domain ) {
    $translated_text = str_replace('Add to cart', 'Přidat do košíku', $translated_text);
    return $translated_text; 
add_filter( 'gettext', 'twiki_translate_string', 100, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Disable WordPress admin bar for all except admins
17. 6. 2021 in
If you have your custom administration for users made with Toolset, you will propably need to hide the admin bar for your users except administrators. So if you have this question: “When you are logged in, the black wordpress top bar is showing up – is it possible to hide this bar for all users […]
Read More
Aleš Sýkora wrote
Use custom Javascript on form submission with Fluent Forms
15. 6. 2021 in
If you need to use your custom script on form submission and using Fluent Forms, use this code in your form’s custom JS settings.
Read More
Aleš Sýkora wrote
Auto login after creating new user with Toolset user form
11. 7. 2019 in
Snippet from our fan.
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram