Bypass cf cache everything for logged in users without cookies Wordpress

Hello guys,

I have tried to tackle this problem by appending query string to every link when admin is logged in, by doing this in funcions.php

function add_admin_qs($url){
if ( is_user_logged_in() ) {
return add_query_arg(‘nocfcache’, ‘true’, $url);
}
}

if ( is_user_logged_in() ) {
add_filter( ‘home_url’, ‘add_admin_qs’, 11, 1);
add_filter( ‘post_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘page_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘post_type_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘category_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘tag_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘author_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘day_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘month_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘year_link’, ‘add_admin_qs’, 11, 1);
}

This code will append query string yoursite/yourpost?nocfcache=true, then you create page rule,
bypass cache 1st: arg *yoursite.com/nocfcache=true

Now when you login to your panel every link page/post will have that query string appended which will tell Cloudflare to bypass those URLs and will not cache your admin data, you can create then these 3 rules:

Bypass *yoursite/nocfcache=true
Bypass yoursite/wp-admin
Cache everything yoursite/
Edit: add wildcards before and after nocfcache=true, the Cloudflare forum editor is stripping them for some reason.

Install Sunny plugin to purge on post/page publish.

This method should work with woocommerce and dynamic logged in users as it will bypass cache for those users, but needs more testing.

I created it for my static websites and news portals, can anyone help me find flaws within this method as it is in beta for me?

Thanks

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.