# Kibble installation contract: section 18 of 29 (guide version 3)

> This is **one section only**, not the whole contract. Complete document: https://www.usekibble.dev/AI/guide.md

## 18. WordPress {#wordpress}

> **Status: importable template.** Structure and logic are tested offline. Not imported into or run on a live platform.

1. Copy the `kibble-analytics` plugin folder to `wp-content/plugins` and activate it. Settings, administrators only: property key, tracking origin, consent mode (manual or Google Consent Mode) and connected hosts.
2. The plugin enqueues the SDK once with escaped data attributes and does nothing until a key and origin are saved. It does not set `data-datalayer`, `data-cookie-domain` or the automatic-candidates option; use the head snippet below if you need those.
3. Wire the consent banner or CMP to `kibble('consent', 'granted' | 'denied')` and re-apply the stored choice on every page load.
4. Register the site host (with its port if non-default) on the property.

- **Contact Form 7:** the SDK itself reports `form_accepted` on `wpcf7mailsent` (mail sent). Do not add your own CF7 hook; it would count twice.
- **WPForms** (AJAX forms, `wpformsAjaxSubmitSuccess`) and **Gravity Forms** (AJAX confirmation, `gform_confirmation_loaded`) call `formAccepted` with the form id as `wpforms_<id>` and `gf_<id>`. A submit that the server rejected is never reported.
- Mark forms with `data-kibble-form` ([Forms](https://www.usekibble.dev/AI#forms)) so starts and validation errors are observed. To line up with the acceptance ids, use `data-kibble-form="wpforms_<id>"` or `data-kibble-form="gf_<id>"`. The plugin does not add markup. Field values are never read.

Without the plugin: functions.php of a child theme or mu-plugin:

```php
<?php
add_action('wp_head', function () { ?>
<script>window.kibble=window.kibble||function(){(window.kibble.q=window.kibble.q||[]).push(arguments)};</script>
<script async src="https://use.example-kibble-host/sdk/v1/kibble.js"
  data-key="pk_YOUR_PROPERTY_KEY" data-endpoint="https://use.example-kibble-host" data-consent="manual"></script>
<?php }, 1);
```

The plugin source is `integrations/wordpress/kibble-analytics` in the Kibble repository. It has been syntax-checked and unit-tested with stubbed WordPress functions only; it has not been activated on a live WordPress site.

END OF SECTION wordpress
