Skip Navigation
December 21, 2020

WordPress includes built in Search functionality, which WPML makes multilingual.

For this to work, two things are required in the search form:

  1. The form needs an ID of searchform.
  2. An input named lang must be set to the current language.

For example, this is the HTML from our own search form:

<form action="" id="searchform" method="get">
  <input type="text" id="s" name="s" value=""/>
  <input type="submit" value="Search" id="searchsubmit"/>
  <input type="hidden" name="lang" value="en"/>

The lang hidden input tells WPML that we’re searching in English. If it was set to ‘es’, it would mean we’re searching in Spanish.

If you want more details on how to set up search on WordPress, visit this article.

Adding the language attribute to the search form

Note: For WPML versions >=3.2 please use the wpml_add_language_form_field action hook. The function shown below can still be used but it has been deprecated and will be removed completely in 3.3

When the searchform ID is set for the form and the lang input exists, WPML limits the search to that language and shows the search results page in the correct language. You can try our own search in different languages and see the results.

WPML’s sitepress.js does this little magic. If your theme prevents this JS from loading, you can do it yourself by manually adding the lang input to search forms and setting its value to the ICL_LANGUAGE_CODE constant.

<input type="hidden" name="lang" value="<?php echo(ICL_LANGUAGE_CODE); ?>"/>

35 Responses to “Search form”

  1. I checked your source AND the search-engine of this website and even the search-engine of this website does not work correctly. If I’m right, you’ve used above solution as well, but when I go to the German page and I’m searching for ‘test’, I still get English results. Even on my blog the solution as told above does not work, it’s very very very frustrating. That it shows the results of other languages is not the biggest problem, but in my sidebar I’ve used a custom query to show the latest 5 posts. On all pages this works fine, but when I use the search-engine, it starts showing translated posts. Can someone help me please??????

  2. Any progress on this? I can confirm on my end that the search seems to be returning all languages – even with the language params that get passed in.

    • We found and fixed the bug and will have a developers version for testing soon. I’ll announce it in the blog.

  3. I am using the latest version with wordpress 3.0 and custom types.The search displays results for all languages.Any help or ideas?

    • Can you post about this in our technical forum? Our support folks will be able to help. Explain exactly what you’re doing and what you’re getting. If you can post a link, they will be able to help you much better.

  4. Wouldn’t it be better to use template_redirect to redirect search results to the correct language? This way if people have custom searchforms on the site it would always work?

    • AJ, what you’re describing would certainly be a valid solution. However, it’s implemented like we describe it in WPML and works just fine. Your custom search form should still work with WPML, as long as the language attribute is included and you are using the WordPress API. WPML filters WordPress API calls.

    • Hi David, I checked it with our developers and they say that should work fine. If it is not working as you expect, please report it in our support forum explaining how to replicate your case.

    • The Real Home is compatible with WPML and was tested by our Compatibility team.

      You configure it to work with WPML the same way you would set up WPML to work with any other theme. If you get lost, use our documentation or support help. To translate your theme’s custom option the String translation module might be needed, so best is to choose at least the “Multilingual CMS” subscription. You can upgrade to the Lifetime subscription later.

  5. How to edit Search Field to search 3 languages. ?

    <input type="text" name="keyword" id="keyword-txt"

  6. It’s not working on my website. I’ve always the result in default language (english) but I’ve selected one of others. (it’s like David Plunkett issue)

    I use the path: http://localhost:3000/fr/support

    <input type="search" value="" name="s" id="s" placeholder="” />

    <input type="hidden" name="lang" value="”/>

    but the result is on: http://localhost:3000/?s=searchquery&lang=fr
    I’m not on the FR version of this website

    So this page is in english (title, desc, results, etc)

    I use Genesis Framework (2.6.1) and WPML (4.0.6)

  7. Hi,

    Just a note. I had the same problem.

    Instead of:


    I’ve got:


    so it didn’t work, and this is what solved it for me:

    <form method="get" id="searchform" action="">

    Altogether it looked like this for me:

    <form method="get" id="searchform"
    <input type="text" size="20" name="s" id="s"
    onblur="if(this.value=='') this.value='';"
    onfocus="if(this.value=='') this.value='';"/>

    Hope it helps for some of you! 😉

    • Please log into your WPML account and start a new thread in our support forum. One of our supporters will assist you with the issue.

    • Could you please open a ticket on our support forum? One of our supporters will look into it. Thank you.