How to concatenate inside the _e() function the right way?

the_search_query() echoes itself, so by putting it into another echo function (what _e() is) you’ll get result as in second example.

It isn’t recommended to use variables or function inside l18n functions, because they can’t be translated, for more information see Otto’s: Internationalization: You’re probably doing it wrong.

So you should use code like this:

printf( __( 'Seach for "%s", 'textdomain' ), get_search_query() );

Note that I’m using get_search_query(), because it simply returns value instead echoing it, also it passes query sting through esc_attr() and no need for esc_html().

Leave a Comment