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 :-).

<?php
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
Featured Image missing after WordPress update
22. 3. 2021 in
Using WordPress + Oxygen builder and can not found featured image in post/page settings? It happend to me after WordPress 5.7 update. If you didn’t disabled it in gutenberg settings, then you might have same problem as me. How to fix it? Install/re-Install theTwenty Twenty-One theme to your website and your featured images will be […]
Read More
Aleš Sýkora wrote
Flickity carousell same height slides fix
24. 3. 2021 in
If you need all your slides to have same height, add the CSS selector to your slider cells and use this code in your CSS: Do not forget to add the cellSelector attribute to your flickity slider setup:
Read More
Aleš Sýkora wrote
Taxonomy Post Count for Custom Post Type
16. 5. 2019 in
Add this snippet to your functions.php or create your own plugin...
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram