Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.