WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to translate the placeholder attribute in my search box. I am using the WPML-plugin to translate all text. How can I accomplish this?

My code:

<input type="search" class="search-field" placeholder="Your Search term here" value="<?php echo esc_attr( $search ); ?>" name="search">
share|improve this question
up vote 0 down vote accepted

Just as any regular string, you can use

<?php esc_attr_e( 'Your Search term here', 'your_theme_slug' ); ?>

So your code for the <input> would look like

<input type="search" class="search-field" placeholder="<?php 
    esc_attr_e( 'Your Search term here', 'your_theme_slug' ); 
    ?>" value="<?php 
    echo esc_attr( $search ); 
    ?>" name="s">

WPML, as well as WordPress, uses the PHP get_text() function. You can translate this either with the additional String Translation Plugin, or you create a mo/po file for your theme.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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