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

# WordPress

> Add your thinnestAI agent to any WordPress site with a simple plugin or embed code.

# WordPress

Add your AI agent to your WordPress site. Works with any WordPress theme — classic editor, block editor, or page builders like Elementor and Divi.

## Method 1: Embed Code (Recommended)

The simplest approach — paste the embed script into your WordPress site.

### Option A: Site-Wide (Header/Footer)

Add the widget to every page on your site:

1. In WordPress admin, go to **Appearance > Theme Editor** (or **Customize > Additional CSS/JS**)
2. Or install a plugin like **Insert Headers and Footers**
3. Add this code to your site's `<head>` or footer:

```html theme={null}
<script
  src="https://app.thinnest.ai/embed.js"
  data-agent-id="YOUR_AGENT_ID"
  data-theme="light"
  data-position="bottom-right"
  async
></script>
```

4. Save and visit your site — the chat bubble should appear

### Option B: Specific Pages Only

Add the widget to individual pages or posts:

1. Edit the page or post
2. Add a **Custom HTML** block (block editor) or switch to **Text** mode (classic editor)
3. Paste the embed code
4. Publish or update the page

### Option C: Elementor

1. Edit your page with Elementor
2. Add an **HTML** widget
3. Paste the embed code
4. Save

### Option D: Divi

1. Edit your page with Divi Builder
2. Add a **Code** module
3. Paste the embed code
4. Save

## Method 2: Custom Plugin

For more control, create a simple WordPress plugin:

### Create the Plugin

1. Connect to your WordPress site via FTP or file manager
2. Navigate to `/wp-content/plugins/`
3. Create a folder: `thinnestai-chat`
4. Create a file `thinnestai-chat.php`:

```php theme={null}
<?php
/**
 * Plugin Name: thinnestAI Chat Widget
 * Description: AI chat widget powered by thinnestAI
 * Version: 1.0
 */

function thinnestai_enqueue_widget() {
    $agent_id = get_option('thinnestai_agent_id', '');
    if (empty($agent_id)) return;

    wp_enqueue_script(
        'thinnestai-embed',
        'https://app.thinnest.ai/embed.js',
        array(),
        null,
        true
    );

    wp_script_add_data('thinnestai-embed', 'data-agent-id', $agent_id);
}
add_action('wp_enqueue_scripts', 'thinnestai_enqueue_widget');

// Settings page
function thinnestai_settings_page() {
    add_options_page(
        'thinnestAI Settings',
        'thinnestAI',
        'manage_options',
        'thinnestai',
        'thinnestai_settings_html'
    );
}
add_action('admin_menu', 'thinnestai_settings_page');

function thinnestai_settings_html() {
    if (!current_user_can('manage_options')) return;

    if (isset($_POST['thinnestai_agent_id'])) {
        check_admin_referer('thinnestai_settings');
        update_option('thinnestai_agent_id', sanitize_text_field($_POST['thinnestai_agent_id']));
        echo '<div class="updated"><p>Settings saved.</p></div>';
    }

    $agent_id = get_option('thinnestai_agent_id', '');
    ?>
    <div class="wrap">
        <h1>thinnestAI Settings</h1>
        <form method="post">
            <?php wp_nonce_field('thinnestai_settings'); ?>
            <table class="form-table">
                <tr>
                    <th><label for="thinnestai_agent_id">Agent ID</label></th>
                    <td><input type="text" id="thinnestai_agent_id" name="thinnestai_agent_id"
                        value="<?php echo esc_attr($agent_id); ?>" class="regular-text" /></td>
                </tr>
            </table>
            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}

// Output embed script with data attributes
function thinnestai_add_widget_script() {
    $agent_id = get_option('thinnestai_agent_id', '');
    if (empty($agent_id)) return;
    ?>
    <script
      src="https://app.thinnest.ai/embed.js"
      data-agent-id="<?php echo esc_attr($agent_id); ?>"
      data-theme="light"
      data-position="bottom-right"
      async
    ></script>
    <?php
}
add_action('wp_footer', 'thinnestai_add_widget_script');
```

5. Activate the plugin in **Plugins > Installed Plugins**
6. Go to **Settings > thinnestAI** and enter your Agent ID

## Configuration

All [widget configuration options](/docs/deploy/web-widget#configuration-options) work in WordPress. Add `data-` attributes to the script tag:

```html theme={null}
<script
  src="https://app.thinnest.ai/embed.js"
  data-agent-id="YOUR_AGENT_ID"
  data-theme="dark"
  data-primary-color="#6366F1"
  data-title="Need Help?"
  data-welcome-message="Hi! Ask me anything about our products."
  data-position="bottom-right"
  async
></script>
```

## Lead Capture

Lead capture works the same as the standard [web widget](/docs/deploy/web-widget#lead-capture). Configure the lead form in your agent's Deploy settings — it will appear in the WordPress widget automatically.

## WooCommerce Integration

For WooCommerce stores, you can pass product context to your agent:

```html theme={null}
<script
  src="https://app.thinnest.ai/embed.js"
  data-agent-id="YOUR_AGENT_ID"
  data-welcome-message="Hi! I can help you find the perfect product."
  async
></script>
```

Your agent's knowledge base can include your product catalog (via URL scraping or file upload) so it can answer product questions accurately.

## Performance

The embed script is:

* **Async loaded** — Does not block page rendering
* **Lightweight** — \~15KB gzipped
* **Lazy initialized** — Widget UI only loads when the user clicks the bubble
* **CDN delivered** — Fast loading worldwide

No impact on your WordPress site's PageSpeed score.

## Troubleshooting

| Issue                        | Solution                                               |
| ---------------------------- | ------------------------------------------------------ |
| Widget doesn't appear        | Check for JavaScript errors in browser console         |
| Conflicts with other plugins | Try loading the script in the footer instead of header |
| Caching issues               | Clear your WordPress cache and CDN cache               |
| CSP errors                   | Add `app.thinnest.ai` to your Content Security Policy  |
| Widget overlaps content      | Adjust `data-position` or add custom CSS margin        |
