• Resolved werdpres

    (@werdpres)


    if logged in as admin and you visit a page where comments are open, it says ‘logged in as admin’ in the comment section

    now if you log out and revisit the same page (or anyone else visits the page), it still says that the admin is logged in because that page is cached

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anonymous User 16850768

    (@anonymized-16850768)

    To disable caching for logged in users (default behavior) you’ll need to ensure the cookies regex option in the Cache Exclusions setting is handling this, like excluding the wordpress_logged_in_ cookie.

    You can customize this to only disable caching for admin users if needed. For example, the following snippet could be added to your functions.php file:

    $user = wp_get_current_user();
    if ( in_array( 'Administrator', (array) $user->roles ) ) {
        setcookie( 'user_admin', 1 );
    }

    The above snippet would set the user_admin=1 cookie for admin users. You could then exclude the user_admin cookie. That would cause the cache to be bypassed for admin users but cached for all other user types.

    Tip: I use the My Custom Functions plugin [by Space-x chimp].

    It’s perfect if you don’t have a child theme with a custom functions file or a custom functions file that won’t get overridden by your theme when it updates.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘admin visited pages being cached’ is closed to new replies.