I’m trying to create a function for the title inside my functions.php, I’m having a problem with the search title part where I have to concatenate here’s the part with issues:

elseif (is_search()) {
_e('Search for ', 'textdomain') . '"' . esc_html(the_search_quey()) . '$quot; - '; }

this one gives a title like this: Search for searchtermsitename

no quotes and the search term is attached to the site name.

I tried this one:

elseif (is_search()) {
_e('Search for ' . '"' . esc_html(the_search_quey()) . '$quot; - ', 'textdomain'); }

it doesn’t work either, this one outputs: searchtermSearch for “” sitename

it’s better than the first one but he search query is before, and can’t figure out why.

so any help, and thanks in advance.

2 Answers
2

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 Reply

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