I'm currently developing a non-trivial theme right now, most of the time I'm not using a __($str) translate function when there's an HTML tag therein the text. Is it good to always use the translate functions such __($str) and _e($str) whenever there's a text that'll be going to output? Any downside with it?

Can I still use it even to a very long text that have mixed with an HTML tag such like this?

__("This <em>text</em> have an <b>HTML</b> tag. Another sentence...")

Or it is good to use like this? (*Looks messy..)

__('This ').'<em>'.__('text').'</em>'.' have an '.'<b>'.__('HTML').'</b>'__(' tag.')

How to properly use such kind of a function?

  • it depends of the sentence. to choose you have to think if it's clear for the translator. in the 2nd case, he will have to translate " have an" and "This " then in this case it would be clearer to translate the whole sentence in one time. when a sentence is to complicated, you can also use sprintf to cut the sentence
    – mmm
    Aug 2, 2015 at 19:11
  • @mmm So you mean translating the whole paragraph that had innerHTML tags works well? Could you provide me a link to an article that proves your saying? Aug 4, 2015 at 7:43
  • 1
    A good information source is the WordPress codex article »I18n for WordPress Developers«. Aug 5, 2015 at 12:43

2 Answers 2


The sweet and short of it all is, never try to translate HTML tags. Use placeholders and either printf or sprintf to translate strings with HTML tags

Something like this will do


printf( __( 'This %s text %s have an %s HTML %s tag. Another sentence...' ), '<em>', '</em>', '<b>', '</b>' );


sprintf( __( 'This %s text %s have an %s HTML %s tag. Another sentence...' ), '<em>', '</em>', '<b>', '</b>' );
  • 1
    @ialocin Thanks for the edit, noddy badge for me for forgetting those brackets :-) Aug 5, 2015 at 12:44
  • 1
    It happens and this is after all a community effort :) Aug 5, 2015 at 12:47

The second option will not only (as @mmm already said) confuse translators, but also the order of words in a sentence can be significantly different from one language to another.

With the first option a translator can adjust and translate properly, which is not possible with the second one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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