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

# WordPress

> Integrate AdXensor into WordPress with the CDN snippet — no plugin required.

AdXensor integrates with WordPress using the CDN snippet. No plugin is required — the script tag is added manually to your theme or through a WordPress hook.

## Adding the AdXensor script

<Tabs>
  <Tab title="functions.php (recommended)">
    This method adds the AdXensor script tag to every page of your site via `wp_enqueue_scripts`.

    <Steps>
      <Step title="Open your theme's functions.php">
        Go to **Appearance → Theme File Editor** in the WordPress admin, or edit the file directly via SFTP/SSH:

        ```
        wp-content/themes/YOUR-THEME/functions.php
        ```
      </Step>

      <Step title="Add the following snippet">
        ```php theme={null}
        <?php
        function adxensor_enqueue_script() {
            wp_enqueue_script(
                'adxensor-tag',
                'https://cdn.adxensor.com/tag.js',
                [],       // no dependencies
                null,     // no version (CDN handles cache busting)
                false     // load in <head>
            );

            // Add data-ad-client attribute and async to the script tag
            add_filter( 'script_loader_tag', function( $tag, $handle ) {
                if ( 'adxensor-tag' !== $handle ) {
                    return $tag;
                }
                return str_replace(
                    '<script ',
                    '<script async data-ad-client="pub-XXXXXXXX" ',
                    $tag
                );
            }, 10, 2 );
        }
        add_action( 'wp_enqueue_scripts', 'adxensor_enqueue_script' );
        ```

        Replace `pub-XXXXXXXX` with your **Site ID**.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Header & Footer plugin">
    If you prefer not to edit code, use a plugin like **Insert Headers and Footers** (by WPCode) or **Header Footer Code Manager**:

    <Steps>
      <Step title="Install and activate the plugin">
        Install and activate the plugin.
      </Step>

      <Step title="Paste the snippet in the Header section">
        Go to the plugin settings and paste this in the **Header** section:

        ```html theme={null}
        <script async
          src="https://cdn.adxensor.com/tag.js"
          data-ad-client="pub-XXXXXXXX">
        </script>
        ```
      </Step>

      <Step title="Save">
        Save.
      </Step>
    </Steps>
  </Tab>

  <Tab title="header.php">
    Edit `header.php` in your theme (`wp-content/themes/YOUR-THEME/header.php`) and paste the script tag before the closing `</head>` tag:

    ```html theme={null}
    <script async
      src="https://cdn.adxensor.com/tag.js"
      data-ad-client="pub-XXXXXXXX">
    </script>
    </head>
    ```

    <Warning>
      **Note**: Editing `header.php` directly will be overwritten when your theme updates. Use a **child theme** or the functions.php method to avoid losing your changes.
    </Warning>
  </Tab>
</Tabs>

## Placing ad slots

Once the script is loaded, place `<ins>` tags anywhere in your theme or page content.

<Tabs>
  <Tab title="Theme template file">
    ```php theme={null}
    <!-- wp-content/themes/YOUR-THEME/single.php (or any template) -->

    <!-- Leaderboard below the site header -->
    <ins class="adxensor"
         style="display:block"
         data-ad-slot="header-banner"
         data-ad-format="728x90">
    </ins>
    ```
  </Tab>

  <Tab title="Block editor (Gutenberg)">
    <Steps>
      <Step title="Add a Custom HTML block">
        Add a **Custom HTML** block where you want the ad.
      </Step>

      <Step title="Paste the snippet">
        Paste the `<ins>` snippet:

        ```html theme={null}
        <ins class="adxensor"
             style="display:block"
             data-ad-slot="in-content"
             data-ad-format="300x250">
        </ins>
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Text widget (classic sidebar)">
    <Steps>
      <Step title="Open Widgets">
        Go to **Appearance → Widgets**.
      </Step>

      <Step title="Add a Custom HTML widget">
        Add a **Custom HTML** widget to your sidebar.
      </Step>

      <Step title="Paste the snippet">
        ```html theme={null}
        <ins class="adxensor"
             style="display:block"
             data-ad-slot="sidebar"
             data-ad-format="300x250">
        </ins>
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Common ad placements

| Placement                   | Slot name suggestion | Recommended format     |
| --------------------------- | -------------------- | ---------------------- |
| Below site header           | `header-banner`      | `728x90`               |
| Above article content       | `above-content`      | `728x90`               |
| In the middle of an article | `in-content`         | `300x250`              |
| Below article content       | `below-content`      | `728x90`               |
| Sidebar widget              | `sidebar`            | `300x250` or `300x600` |
| Mobile sticky footer        | `mobile-footer`      | `320x50`               |
| Between related posts       | `related-posts`      | `300x250`              |

## Responsive ads

Use `data-ad-format="auto"` to let AdXensor automatically pick the best size for the visitor's device:

```html theme={null}
<ins class="adxensor"
     style="display:block"
     data-ad-slot="responsive-banner"
     data-ad-format="auto">
</ins>
```

Auto-sizing rules:

| Device  | Breakpoint      | Chosen format                    |
| ------- | --------------- | -------------------------------- |
| Mobile  | width \< 768 px | `320x50` or `300x250`            |
| Tablet  | 768–1023 px     | `468x60` or `300x250`            |
| Desktop | ≥ 1024 px       | `728x90`, `468x60`, or `300x250` |

## WooCommerce

AdXensor slots work on WooCommerce pages the same way as regular WordPress pages. Add slots using the Custom HTML block in WooCommerce page templates or use hooks:

```php theme={null}
// Show a banner above the WooCommerce shop loop
add_action( 'woocommerce_before_shop_loop', function() {
    echo '<ins class="adxensor" style="display:block"
               data-ad-slot="shop-top"
               data-ad-format="728x90"></ins>';
}, 10 );
```

## Verifying the integration

<Steps>
  <Step title="Visit your website">
    Visit your website in a browser.
  </Step>

  <Step title="Open DevTools and filter by adxensor">
    Open **DevTools → Network** and filter by `adxensor`.
  </Step>

  <Step title="Check the requests">
    You should see a request to `cdn.adxensor.com/tag.js` and then to `core.adxensor.com/v1/ad`.
  </Step>

  <Step title="Confirm in the dashboard">
    In the **AdXensor Publisher Dashboard**, go to **My Sites → \[Your Site] → Statistics** and confirm that pageview events appear within a few minutes.
  </Step>
</Steps>

## Troubleshooting

| Symptom                 | Solution                                                                                                      |
| ----------------------- | ------------------------------------------------------------------------------------------------------------- |
| Script not loading      | Check that `wp_head()` is called in your `header.php` (it should be just before `</head>`)                    |
| Slots not filling       | Verify your Site ID and that the site status is **Active** in the dashboard                                   |
| Plugin conflicts        | Some security plugins (Wordfence, iThemes Security) may block external scripts — whitelist `cdn.adxensor.com` |
| `display:none` on slots | Always include `style="display:block"` on the `<ins>` tag                                                     |

→ [Full troubleshooting guide](/publishers/support/troubleshooting)
