How disable FLoC for your visitors

If you use Google Chrome, your browser will probably track the websites you visit. All the data are collected through the so-called Federated Learning of Cohorts (FLoC).

 

How to disable FLoC without plugin.

You can disable FLoC for your website with this code:

add_filter( 'wp_headers',function( $headers ){
    if( !$headers || !is_array( $headers ) ) $headers = array();
    if( empty( $headers ) || !isset( $headers['Permissions-Policy'] ) || empty( $headers['Permissions-Policy'] ) ){
        $headers['Permissions-Policy'] = 'interest-cohort=()';
        return $headers;
    }
    $policies = explode( ',',$headers['Permissions-Policy'] );
    // Check for existence of FLoC directive.
    foreach( $policies as $n => $policy ){
        $policies[$n] = $policy = trim( $policy );
        if( false !== stripos( '_'.$policy,'interest-cohort' ) ) {
            //If directive present we don't do anything
            return $headers;
        }
    }
    //Add policy to disable FLoC
    $policies[] = 'interest-cohort=()';
    $headers['Permissions-Policy'] = implode( ', ',$policies );
    return $headers;
} );

How to disable FLoC using a plugin.

If you prefer it, you can also install the plugin Flic FLoC. It’s an ultra-lightweight plugin that just includes the code above.

No options, no queries It does nothing but writing a header to disable FLoC for your website.

How to check if FLoC is disabled for your website.

If you want to check if the code or the plugin worked for you:

  • Inspect elements (usually F12 or right-click => Inspect Elements)
  • Click on Network
  • Refresh the page
  • If you see permissions-policy: interest-cohort=() it worked

If you have any caching system, delete all the cache including the cache of the headers.