# Remove Ad Click IDs From Links in Your Content

> Strips tracking parameters such as fbclid, gclid, msclkid and Mailchimp or HubSpot IDs from links in your posts (often pasted in by accident), so you do not pass your visitors' ad tracking along to other sites.

- Type: PHP
- Runs: Frontend only
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: links, tracking, content
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-strip-click-ids-from-links/

## Code

```php
// Query parameters removed from links.
$wpide_click_ids = array( 'fbclid', 'gclid', 'gbraid', 'wbraid', 'dclid', 'msclkid', 'yclid', 'igshid', 'mc_cid', 'mc_eid', '_hsenc', '_hsmi', 'ttclid', 'twclid', 'li_fat_id' );

add_filter( 'the_content', function ( $content ) use ( $wpide_click_ids ) {
    if ( ! preg_match( '/[?&](' . implode( '|', array_map( 'preg_quote', $wpide_click_ids ) ) . ')=/', $content ) || ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
        return $content;
    }

    $tags = new WP_HTML_Tag_Processor( $content );

    while ( $tags->next_tag( 'a' ) ) {
        $href = (string) $tags->get_attribute( 'href' );
        if ( false !== strpos( $href, '?' ) ) {
            $clean = remove_query_arg( $wpide_click_ids, $href );
            if ( $clean !== $href ) {
                $tags->set_attribute( 'href', $clean );
            }
        }
    }

    return $tags->get_updated_html();
}, 20 );
```

## Notes

UTM campaign tags are kept on purpose; add utm_source and friends to the list if you want those removed too.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Ad Click IDs From Links in Your Content" 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/
