0

I've been searching thru all WordPress files for the phrase "search result for", which is displayed on the search result page (search result for (keywords)) but can't find it.

I would like it to be: "You searched for: (keywords)"

Does anybody know where and how to change this?

2
  • the string is with an 's' on results - 'search results for'. Looks like it's in the language files so could be edited there or with a child theme perhaps
    – mozboz
    Commented Jul 10, 2020 at 12:37
  • This would depend entirely on how your theme is constructed. I suggest asking its author. Commented Jul 10, 2020 at 14:21

3 Answers 3

0

I fixed this by adding the following JavaScript in my theme:

addEventListener("DOMContentLoaded", () => {
  if (window.location.href.includes("?s=")) {

    // You might need to use adjust the archive title selector
    // according to the specific class of your header, for example:
    // const archiveTitle = document.querySelector(".elementor-heading-title");

    const archiveTitle = document.getElementByTagName('H1')[0];

    if (!!archiveTitle) {
      let text = archiveTitle.innerText;
      text = text.replace("Search Results For: ", "Resultados de la búsqueda de: ");
      archiveTitle.innerText = text;
    }
  }
});

This has disadvantage of creating FLUC (flash of un-styled content).

0

From your current theme, I recommend creating a child theme using this plugin https://wordpress.org/plugins/child-theme-configurator/. Within the code of the theme, you will find a folder named template-parts which contains some php files, such as search.php. You should now create the same pattern in your child theme, the folder template-parts, and inside it the file search.php with the same content as the original one, and now simply edit the text you mentioned in this newly created file.

-1
add_filter('document_title_parts', function($parts){
    if( is_search() ){
        $parts['title'] = sprintf('You searched for: %s',get_search_query());
    }
    return $parts;
});
5
  • well, WordPress didn't crash, but my text didn't change...
    – JoBe
    Commented Jul 10, 2020 at 13:26
  • @JoBe how you search template file calls?
    – Az Rieil
    Commented Jul 10, 2020 at 14:03
  • how do I do what?
    – JoBe
    Commented Jul 10, 2020 at 14:23
  • What is name of search template file you using? Its your theme or you working with existing?
    – Az Rieil
    Commented Jul 10, 2020 at 14:25
  • I'm using hello by elementor...
    – JoBe
    Commented Jul 10, 2020 at 15:36

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.