How to disable FLoC in WordPress

Last updated:

This article explains how to disable FLoC in WordPress. It explains how to use plugins, hooks, and even how to write a web server configuration file.

What is FLoC?

FLoC is an acronym for Federated Learning of Cohorts.

It is a method that uses machine learning algorithms to analyze the data of users who visit a website and create a “cohort” of users with the same interests.

FLoC tracks behavior by cohort, not by individual. Based on the tracked data, ads are targeted.

Google has announced that it will adopt FLoC as a replacement for third-party cookies in Chrome.

How to disable FLoC in WordPress

To disable FLoC, add “Permissions-Policy interest-cohort=()” to the HTTP header.

Using Plugins

WordPress provides a plugin to disable FLoC.

Disable FLoC

Disable FLoC

Disable FLoC

Disable FLoC

Using a Hook

Add the following code to your theme’s functions.php

function disable_floc($headers) {
    $headers['Permissions-Policy'] = 'interest-cohort=()';
    return $headers;
} 
add_filter('wp_headers', 'disable_floc');

If you want to determine the Permissions-Policy and then add it, add the following code.

function disable_floc( array $headers ) : array {
    $permissions = [];
    if ( ! empty( $headers['Permissions-Policy'] ) ) {
        // Abort if cohorts has already been added.
        if ( strpos( $headers['Permissions-Policy'], 'interest-cohort' ) !== false ) {
            return $headers;
        }
        $permissions = explode( ';', $headers['Permissions-Policy'] );
    }
    $permissions[] = 'interest-cohort=()';
    $headers['Permissions-Policy'] = implode( ',', $permissions );
    return $headers;
}
add_filter( 'wp_headers', 'disable_floc' );

Configure on the Web server

Apache

Write the following in .htaccess

<IfModule mod_headers.c>
Header always set Permissions-Policy interest-cohort=()
</IfModule>

NGINX

Write the following in the configuration file

add_header Permissions-Policy interest-cohort=();

How to check the HTTP header

Check to see if “Permissions-Policy interest-cohort=()” has been added to the HTTP header.

Here is a web service that allows you to check HTTP headers.

In Security Headers, you can check the HTTP headers by entering the URL.

Security Headers

If FLoC cannot be disabled

If you are using a cache plugin, you will need to clear the cache.

Also, some cache plugins remove HTTP headers. Check if there is an option about HTTP headers in the plugin.

go to top