# Add AI chat to a WordPress site

> Crawl your WordPress site from its sitemap, then paste the chat widget into your footer. Your agent answers from your posts and pages with sources.

AskVault reads your WordPress posts and pages from your sitemap, then you paste one script tag into your site footer to show the chat. The agent answers from what you published and shows the pages each answer came from.

It works with any modern theme and page builder, including Elementor, Divi and Astra, and on WordPress.com sites that allow custom scripts. The Free plan covers it. 

## Before you start

- Admin access to WordPress.
- A public site. AskVault reads published pages only: not drafts, private or password-protected posts, comments, or pages your `robots.txt` disallows.
- An AskVault account. Sign up at [askvault.co/signup](https://askvault.co/signup).

## Step 1: teach your agent your site

WordPress 5.5 and later publishes a sitemap at `/wp-sitemap.xml` and lists it in `robots.txt`. SEO plugins such as Yoast or Rank Math publish their own, often `/sitemap_index.xml`. AskVault finds either automatically.

#### New dashboard

1. For a new agent, paste your site's address in the setup screen.
2. For an existing agent, open **Knowledge** in the sidebar, under **Your agent**, and add your site's address as a website.
3. Optionally exclude archive listings such as `/tag/` and `/category/`.

#### Previous dashboard

1. For a new agent, paste your site's address in the onboarding screen.
2. For an existing agent, open **Knowledge**, choose **Add Source**, pick the web crawler and enter your site's address.
3. Optionally add rules to leave out archive listings such as `/tag/` and `/category/`.

Limits per crawl:

- Discovery ranks up to 50,000 sitemap URLs and keeps the most useful 5,000.
- Pages kept: as many as fit in your plan's content storage allowance (5 MB on Free). There is no separate page limit.

See [add your website](/knowledge/add-your-website/) and [choose which pages to read](/knowledge/choose-pages/).

## Step 2: add the chat widget

AskVault has a WordPress plugin that loads the widget from a pasted token and adds a help button to WooCommerce order pages. It is not listed in the WordPress plugin directory, so searching for it under **Plugins**, **Add New** finds nothing. Install the widget with one of the methods below. For the order button, see [connect WooCommerce](/stores/woocommerce/).

Copy your script tag from **Channels** (see [add the chat widget to your website](/channels/website-widget/)). Then use one of these methods.

### A code snippets plugin (easiest)

A snippets plugin adds the script site-wide and survives theme updates.

1. In WordPress, go to **Plugins**, **Add New**, install a code snippets plugin such as Code Snippets or WPCode, and activate it.
2. Add a new **HTML** snippet called "AskVault chat widget" and set it to load in the **site footer**.
3. Paste your script tag and save the snippet as active.
4. Open your site in a private window. The chat launcher appears.

### Your child theme's footer.php

Use this if you already maintain a child theme. Editing a parent theme directly is risky, because the next theme update erases your change.

1. Go to **Appearance**, **Theme File Editor** and select your child theme.
2. Open **footer.php**, find the closing `</body>` tag and paste the script tag on the line above it.
3. Click **Update File**.

Block themes (Twenty Twenty-Two and later) have no `footer.php`. Use the snippets plugin or Google Tag Manager instead.

### Google Tag Manager

If your site already loads Tag Manager, keep the widget there: create a **Custom HTML** tag, paste your script tag, set the trigger to **All Pages** and publish the container. Add `/cart/` or `/checkout/` as trigger exceptions to hide the widget on those pages.

To show the widget only to signed-in users, wrap the tag in a PHP check in a snippet:

```php
<?php if ( is_user_logged_in() ) : ?>
  <!-- paste your AskVault script tag here -->
<?php endif; ?>
```

## Keep your answers current

There is no on-publish sync. After you publish or edit posts, use **Resync** on the Knowledge page for changed pages, and add the site again to pick up new posts. Paid plans can also schedule automatic re-checks. See [keep your agent up to date](/knowledge/keep-up-to-date/).

Pages behind a membership login can be read with a session cookie. See [pages behind a login](/knowledge/pages-behind-login/).

## WooCommerce stores

If you run WooCommerce, connect the store so the agent can look up orders and recommend products from your catalogue. See [connect WooCommerce](/stores/woocommerce/).

## Check it worked

1. Open your site in a private window and confirm the launcher appears.
2. Ask a question your posts answer. The reply shows its sources.
3. Send a test message and find it in your [Inbox](/inbox/).

## If it doesn't work

**Only the homepage was indexed.** AskVault could not find a sitemap. Open `https://yoursite.com/wp-sitemap.xml` (or your SEO plugin's sitemap) to check it loads, and make sure search-engine visibility is not switched off under **Settings**, **Reading**, which also disables the sitemap.

**Answers include menu or footer text.** Re-add the affected pages as exact links with a CSS selector for your theme's content area, for example `.entry-content`.

**The launcher does not appear.** Caching plugins such as WP Rocket, W3 Total Cache and LiteSpeed Cache can serve signed-in admins an old page. Clear the cache or check in a private window.

**"AskVault is not defined" in the browser console.** An old chat plugin or a second copy of the script may be loading. Remove the duplicate.

## Common questions

### Does this work on WordPress Multisite?

Yes. Each site can load its own agent token, so each site gets its own knowledge.

### Will SEO plugins still work?

Yes. The chat panel is drawn by the widget and not added to your page's HTML, so Yoast, Rank Math and AIOSEO keep working as before.

### Can I leave specific posts out?

Add an exclude rule for their path, or delete them from the Knowledge page after the crawl.

## Related

- [Add the chat widget to your website](/channels/website-widget/)
- [Connect WooCommerce](/stores/woocommerce/)
- [Channels](/channels/)

Source: https://docs.askvault.co/channels/wordpress/
