# Pinterest Tag

> Adds the Pinterest tag to every public page and records page visits, with an option to wait for cookie consent.

- Type: PHP
- Runs: Frontend only
- Category: [Analytics & Tracking](https://wpide.com/library/category/analytics/)
- Tags: pinterest, pixel, tracking, ads
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/analytics-pinterest-tag/

## Code

```php
add_action( 'wp_head', function () {
    $tag_id          = 'YOUR_TAG_ID'; // Pinterest tag ID.
    $require_consent = false;         // true: wait for consent from the WPIDE cookie banner.

    if ( 'YOUR_TAG_ID' === $tag_id || current_user_can( 'edit_posts' ) ) {
        return;
    }
    ?>
<script>
(function (run) {
    if (!<?php echo $require_consent ? 'true' : 'false'; ?> || /(?:^|; )wpide_consent=granted/.test(document.cookie)) { run(); return; }
    document.addEventListener('wpide:consent', function (e) { if (e.detail === 'granted') { run(); } });
})(function () {
    if (!window.pintrk) {
        window.pintrk = function () { window.pintrk.queue.push(Array.prototype.slice.call(arguments)); };
        window.pintrk.queue = [];
        window.pintrk.version = '3.0';
        var s = document.createElement('script');
        s.async = true;
        s.src = 'https://s.pinimg.com/ct/core.js';
        document.head.appendChild(s);
    }
    pintrk('load', <?php echo wp_json_encode( $tag_id ); ?>);
    pintrk('page');
});
</script>
    <?php
} );
```

## Notes

Replace YOUR_TAG_ID with the tag ID from Pinterest Ads Manager > Conversions; nothing is output while the placeholder is in place.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Pinterest Tag" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
