Code snippet to disable caching for logged in users

Hey @everyone,

I’ve spotted several topics that relate to users not having disabled caching for logged-in users. Many caching plugins don’t have this exact option, so here’s a snippet I thought I’d share with the community that you can add with the Code Snippets plugin for easy maintenance.

add_action( 'init', function() {
    if ( is_user_logged_in() ) {
        if ( ! defined( 'DONOTCACHEPAGE' ) ) {
            define( 'DONOTCACHEPAGE', true );
        }
    }
});

I hope the community finds this useful!

Cheers,
Chris :victory_hand:

1 Like

Thank you for the solution! This will be very helpful for our community.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.