Tip: Translating complex strings in WordPress

Remi | May 31, 2012 | in Tips

Very often i see people that don’t really bother about translation when they work on a WordPress project (theme or plugin), and it’s really annoying when you want to use the code with another language. And what happen is that when people deal with internationalization, they don’t do it that well… So this little tip is just to remind you that when you need to translate strings that contain variable elements, there’s a way to it simply, just have a look at the code above:

The author

About the author Remi: Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!


  1. Rémy

    How can we handle translated strings with html in it ? For example, a header title with a span inside to apply some styling for a part of the text ? Is it necessary to translate them separetely ?

    1. Rémi Post author

      Actually this is a bad practice, translatable strings shouldn’t contain HTML tags. I encourage you to have a look to these functions: esc_attr__(), esc_attr_e(), esc_html__() and esc_html_e()

  2. kress

    Remi, what do you think about translating wordpress strings with localization tools? I would totally recommend https://poeditor.com/ as a good method to do it. Except for its user-friendly interface and helping features for translators, it also has a plugin for wordpress that allows you to transfer your translated strings directly on your website. What do you think?

Leave a reply