> ## Documentation Index
> Fetch the complete documentation index at: https://sitegpt.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Use SiteGPT as your site search

> Let visitors ask your chatbot from a search box on your page: show the chat inside the page, or send the text from your own search bar to the chat.

You can put SiteGPT where visitors expect a search box, for example on your home page or your help center. The chatbot then answers the question from your content, in the chat.

SiteGPT has no separate search bar embed. There are two ways to do this with the chat widget:

| Way | What the visitor sees | Code |
| - | - | - |
| [Show the chat inside the page](#show-the-chat-inside-the-page) | A chat box in your page. The visitor types the question in the chat's own message box. | Copy and paste only |
| [Send your search bar to the chat](#send-your-search-bar-to-the-chat) | Your own search box. When the visitor submits it, the chat window opens with the question and the answer. | A short script |

## Before you start

* Role: Manager or higher on the chatbot to copy the code from the **Installation** page. See [Invite and manage team members](https://sitegpt.ai/docs/guides/account/team-members.md).
* Access to the HTML of your page, or to a block or element in your website builder that takes HTML and scripts.
* Your chatbot ID. It is on the **Installation** page.

## Show the chat inside the page

Use the inline container. The chat shows in a box on your page, and the floating chat icon does not show.

**1. Copy the Inline Container code**

On the **Installation** page, in **Embed Options**, find **Inline Container**. Select **Copy**.

**2. Paste the code where the search box goes**

Paste the code in your page, at the place where you want visitors to ask. For a search-style box, make the container shorter, for example `height: 400px`.

**3. Remove the other embed code from that page**

If this page also has the JavaScript embed code, remove it from this page. The inline code already loads the chat with `hideBubble=true`.

The code looks like this:

```html theme={null}
<!-- Add container(s) where you want the chat -->
<div class="sitegpt-chat-widget" data-sitegpt-id="YOUR_CHATBOT_ID" style="width: 100%; height: 400px;"></div>

<!-- Include the JavaScript embed code with ?hideBubble=true -->
<script type="text/javascript">window.$sitegpt=[];(function(){d=document;s=d.createElement("script");s.src="https://sitegpt.ai/widget/YOUR_CHATBOT_ID.js?hideBubble=true";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();</script>
```

To change what the chat says before the visitor asks, for example a welcome message or starter questions, see [Conversation starters](https://sitegpt.ai/docs/guides/widget/conversation-starters.md). For more about the inline container, see [Show the chat inside a page](https://sitegpt.ai/docs/guides/install/control-where-it-appears.md#show-the-chat-inside-a-page).

### On WordPress

> [tab] With the SiteGPT plugin
>
> The plugin already loads the chat on every page. Add only the container.
>
> 1. Open the page in the WordPress editor.
> 2. Add a **Custom HTML** block where the search box goes.
> 3. Paste only the `<div>` line of the code, not the `<script>`.
> 4. Update the page.
>
> The plugin also shows the floating chat icon on this page. To hide the icon on this page only, add the page path to [Excluded Pages](https://sitegpt.ai/docs/guides/install/control-where-it-appears.md#hide-the-chat-icon-on-some-pages). Excluded Pages does not hide the chat inside the page.

> [tab] Without the plugin
>
> 1. Open the page in the WordPress editor.
> 2. Add a **Custom HTML** block where the search box goes.
> 3. Paste the full Inline Container code.
> 4. Update the page.
>
> If WordPress removes the `<script>` when you save, keep the `<div>` in the block. Then add the `<script>` part to the footer of that page with a plugin that adds header and footer code.

## Send your search bar to the chat

Keep your own search box. When the visitor submits it, your page sends the text to the chat with the [widget SDK](https://sitegpt.ai/docs/developers/widget-sdk.md#send-or-prefill-a-message). The chat window opens, sends the question, and shows the answer. You do not need to open the chat first.

**1. Add the embed code to the page**

The page needs the normal JavaScript embed code, or the WordPress plugin. See [Add SiteGPT to your website](https://sitegpt.ai/docs/guides/install/add-to-website.md). If the chat icon already shows on the page, this is done.

**2. Add the search box and the script**

Paste this code where the search box goes. You can change the label, the placeholder, the button text, and the style.

**3. Test it**

Open the page, type a question in the search box, and press Enter or select **Ask**.

```html theme={null}
<form id="sitegpt-search" role="search">
  <label for="sitegpt-search-input">Ask a question</label>
  <input id="sitegpt-search-input" type="search" placeholder="How do I reset my password?" required>
  <button type="submit">Ask</button>
</form>

<script>
  document.addEventListener('submit', function (event) {
    if (!event.target || event.target.id !== 'sitegpt-search') return;
    event.preventDefault();
    var input = document.getElementById('sitegpt-search-input');
    var question = input.value.trim();
    if (!question || !window.$sitegpt) return;
    window.$sitegpt.push(['do', 'message:send', question]);
    input.value = '';
  });
</script>
```

How it works:

* The script listens for the form's submit on the whole page, so it works above or below the form, in the header or in the footer.
* `event.preventDefault()` stops the form from loading a search results page.
* `window.$sitegpt.push(['do', 'message:send', question])` sends the text as the visitor's message. The answer shows in the chat window.
* Each question goes into the visitor's current conversation, so the visitor can ask follow-up questions in the chat.
* A visitor message has a length limit. If the text is too long, the chat does not send it and shows an error. See [Chat message length](https://sitegpt.ai/docs/reference/plans-and-limits.md#chat-message-length).

To show only your search box and not the chat icon, add `hideButton=true` to the script URL of the embed code: `.../widget/YOUR_CHATBOT_ID.js?hideButton=true`. The chat window still opens when the visitor submits the search box. See [Embed code options](https://sitegpt.ai/docs/guides/install/add-to-website.md#embed-code-options).

### On WordPress

1. Install the SiteGPT plugin, or check that it is active. See [Add SiteGPT to your website](https://sitegpt.ai/docs/guides/install/add-to-website.md).
2. Open the page in the WordPress editor.
3. Add a **Custom HTML** block where the search box goes.
4. Paste the search box code from above.
5. Update the page.

If WordPress removes the `<script>` when you save, keep the `<form>` in the block. Then add the `<script>` part to the footer with a plugin that adds header and footer code.

The plugin adds the chat with its default options, so the chat icon stays on the page. Do not add this page to Excluded Pages. On an excluded page, the chat does not open from your search box.

## Check that it works

1. Open the page in a new private browser window.
2. Ask a question that your content answers.
3. The chat shows the question and the answer.

## If it does not work

> [accordion] Nothing happens when I submit the search box
>
> * Check that the embed code or the WordPress plugin is on the page. View the page source and search for `sitegpt.ai/widget`.
> * Check that the `id` values in the form and the script match.
> * If the page is in **Excluded Pages**, the chat does not open there, unless the embed code uses `hideButton=true` or `hideBubble=true`. Remove the page from Excluded Pages. See [Hide the chat icon on some pages](https://sitegpt.ai/docs/guides/install/control-where-it-appears.md#hide-the-chat-icon-on-some-pages).
> * If you set **Allowed Domains**, your website's domain must be in the list. See [Allow only your own websites](https://sitegpt.ai/docs/guides/install/control-where-it-appears.md#allow-only-your-own-websites).
> * Open the browser console. Messages from SiteGPT start with `SiteGPT:`.

> [accordion] The page reloads or opens a search results page
>
> The script did not run, so the form did its normal submit. Check that the `<script>` is on the page and that your website builder did not remove it. Check that the form has `id="sitegpt-search"`.

> [accordion] The floating chat icon shows next to the chat inside the page
>
> The page has the normal embed code, or the WordPress plugin, as well as the inline code. Remove the normal embed code from that page. With the WordPress plugin, add the page to Excluded Pages.

## Related

* [Control where the chatbot appears](https://sitegpt.ai/docs/guides/install/control-where-it-appears.md)
* [Widget SDK](https://sitegpt.ai/docs/developers/widget-sdk.md)
* [Add SiteGPT to your website](https://sitegpt.ai/docs/guides/install/add-to-website.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.