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
    Jul 10, 2020 at 12:37
  • This would depend entirely on how your theme is constructed. I suggest asking its author. Jul 10, 2020 at 14:21

2 Answers 2

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).

-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
    Jul 10, 2020 at 13:26
  • @JoBe how you search template file calls?
    – Az Rieil
    Jul 10, 2020 at 14:03
  • how do I do what?
    – JoBe
    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
    Jul 10, 2020 at 14:25
  • I'm using hello by elementor...
    – JoBe
    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.