Skip to main content

Exclude Specific User Roles from Logged-in Cache

Updated this week

When the "Cache for Logged-in Users by Role" option is enabled in FlyingPress, separate cache versions are generated for each user role. If you want to exclude certain roles from being cached (e.g., administrators or shop managers), you can use the flying_press_cache_excluded_roles filter.

Where to add this code

Add the filter to one of the following:

  • Your theme’s functions.php file

  • A custom plugin

  • A plugin like Code Snippets

Example: Exclude administrators and shop managers

add_filter('flying_press_cache_excluded_roles', function ($roles) {
return ['administrator', 'shop-manager'];
});

This will disable caching for users with those roles, ensuring they always see the uncached version of the site.

Notes

  • The array must include WordPress role slugs

  • This filter only applies when “Cache logged-in users” is enabled

  • All other roles will continue to be cached individually unless excluded here

Did this answer your question?