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">

1 Answer 1


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.

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.