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.

Most Popular Articles

  1. How to Add width/height to Images in WordPress
  2. How to check if the current user is Administrator in WordPress
  3. How to disable lazy loading of iframe in WordPress
  4. What’s changing in WordPress 5.7? New Features and Changes
  5. WordPress 5.7.1 Update Includes 2 Vulnerabilities and 26 Bug Fixes
  6. WordPress 5.6 jQuery version updates and solution for jQuery
  7. WordPress Version List (Release Date/Code Name)
  8. How to use the current_user_can function in WordPress
  9. What’s new in WordPress 5.6? New Features and Changes
  10. WordPress Template Tags (162 Types)

New Articles

go to top