# WordPress

> Add the Taggor snippet to a WordPress site without a plugin, and place a component in a block.

Requirements: a self-hosted WordPress 6.3 or newer, access to the theme's `functions.php` (or the ability
to add a small plugin), and one of the site's two site keys: the **production** key for the live site, the **staging** key for a test copy (`npx taggor sites list` shows both; [Sites and environments](https://taggor.dev/docs/sites.md) explains them).

## Install the snippet once

Add this to your theme's `functions.php` (a child theme, so an update does not remove it) or to a small
plugin of your own:

```php title="functions.php"
add_action( 'wp_enqueue_scripts', function () {
	wp_enqueue_script( 'taggor', 'https://cdn.taggorcdn.com/s/<site-key>.js', array(), null, array( 'strategy' => 'async', 'in_footer' => true ) );
} );
```

`wp_enqueue_script` with the `async` strategy and `in_footer` loads the script without blocking the page
and is available from WordPress 6.3
([WordPress Developer Resources: wp_enqueue_script](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)).
The `null` version keeps WordPress from adding `?ver=` to the address.

## Place the component

In the block editor, add a **Custom HTML** block and write the component's tag:

```html title="Custom HTML block"
<contact-form headline="Ask for a quote"></contact-form>
```

Put the text of the component inside the tag, as children. Text written inside the tag is part of the page's HTML:

```html
<faq-accordion items='[{"question":"Do you deliver on weekends?","answer":"Yes, on Saturdays."}]'>
  <h2>Do you deliver on weekends?</h2>
  <p>Yes, on Saturdays.</p>
</faq-accordion>
```

## Compatibility

Components on a real WordPress 7.1.4 with the Twenty Twenty-Five and Twenty Twenty-Four themes, and
with Elementor 4.3.5 on Twenty Twenty-Five, in Chromium, Firefox and WebKit, in a Custom HTML block (an HTML
widget in Elementor). The `async` snippet next to a page's import map, as WordPress prints for its own
blocks, works in the same three browsers. See
[Browser and platform compatibility](https://taggor.dev/docs/browser-support.md).

## Limits

- The Custom HTML block keeps a script tag only for users with the `unfiltered_html` capability; that does not
  matter here, because the script comes from `functions.php` and the block holds only the tag. On a
  multisite, only the Super Admin has the capability ([Unfiltered MU](https://wordpress.org/plugins/unfiltered-mu/)).
- On WordPress.com, code needs a plan that allows plugins; free sites do not accept it
  ([WordPress.com Support: code](https://wordpress.com/support/code/)).
- Page caches and optimizers that combine or delay scripts can change when the snippet runs. The loader
  waits for the page to finish parsing before it loads anything, so it does not break the page's own
  import map.

## Common problems

- **The component does not appear.** Open the page source and look for the snippet's script tag. A cache
  plugin may serve the old page: clear it. The tag in the block must be written exactly as the component
  names it, with a hyphen.
- **A block shows the tag as text.** The tag was typed in a paragraph block, not in Custom HTML.
