Support » Developing with WordPress » Custom Search bar

  • Hi,

    I need a custom Search Bar.
    if a certain word is searched, it should automatically open a URL.

    example: search for ‘hello’ opens http://www.abc.com/hello

    i know how to set up a page with /hello 🙂

    But i need a fully customizable search bar.

    Every help is much appreciated
    thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    That would work if the URL contained search, like http://www.abc.com/search/hello
    But it’s not a good idea to let your users dictate your URLs like your example. The example would clash with any existing Pages that you have.

    Thread Starter ct1601

    (@ct1601)

    Can you please give me an introduction on how to set this up?

    Much thanks for your reply

    Moderator bcworkz

    (@bcworkz)

    Add a rewrite rule that matches the “search” URL element and passes the subsequent element as the value to the “s” query var.
    https://developer.wordpress.org/reference/functions/add_rewrite_rule/

    For example, if the request were example.info/search/foo/, the rewritten URL would then be example.info/index.php?s=foo You also need your search form to make such a request. A form could make the rewritten URL request (s=foo) on its own, but if you want a /search/foo/ sort of request, it’ll take some JavaScript to construct the URL and submit it instead of allowing the form default to work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.