# "Do Not Sell or Share My Personal Information" Link

> Adds a [do_not_sell_link] shortcode for the opt-out link US state privacy laws such as the CCPA require; clicking it records the visitor's opt-out in a cookie and tells marketing scripts held back by consent snippets not to run.

- Type: PHP
- Runs: Frontend only
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: ccpa, opt-out, cookies
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-do-not-sell-link/

## Code

```php
add_shortcode( 'do_not_sell_link', function ( $atts ) {
    static $script = false;

    $atts = shortcode_atts( array( 'text' => 'Do Not Sell or Share My Personal Information' ), $atts, 'do_not_sell_link' );
    $html = '<button type="button" class="wpide-optout" style="background:none;border:0;padding:0;color:inherit;text-decoration:underline;cursor:pointer;font:inherit;">' . esc_html( $atts['text'] ) . '</button><span class="wpide-optout-status" role="status" style="margin-left:.5em;"></span>';

    if ( ! $script ) {
        $script = true;
        $html  .= '<script>(function(){function out(){return /(?:^|; )wpide_optout=1/.test(document.cookie)||navigator.globalPrivacyControl===true;}function mark(){document.querySelectorAll(".wpide-optout-status").forEach(function(s){s.textContent=out()?"You have opted out.":"";});}document.addEventListener("click",function(e){if(!e.target.closest(".wpide-optout")){return;}document.cookie="wpide_optout=1;path=/;max-age="+(365*86400)+";SameSite=Lax"+(location.protocol==="https:"?";Secure":"");document.cookie="wpide_consent=denied;path=/;max-age="+(365*86400)+";SameSite=Lax";document.dispatchEvent(new CustomEvent("wpide:consent",{detail:"denied"}));mark();});document.addEventListener("DOMContentLoaded",mark);})();</script>';
    }

    return $html;
} );
```

## Notes

Visitors who send the Global Privacy Control signal are treated as opted out automatically; your marketing tools still need to respect the wpide_optout cookie or the consent helpers.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Do Not Sell or Share My Personal Information" Link" 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/
