WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a site that allows user registration and login but not via the standard wp-login.php etc - it's all done within the theme and a bit of s2member as well.

I've been encountering problems where, with page caching enabled, my code shows either a login button or a 'your account' button, showing cached material.

I use the below code to decide which button is shown depending on whether the right user level member is logged in.

<?php if (current_user_is("s2member_level1")) : ?>
        $current_user = wp_get_current_user();
        $redirect = '&amp;redirect_to='.urlencode(wp_make_link_relative(get_option('siteurl')));
        $uri = wp_nonce_url( site_url("wp-login.php?action=logout$redirect", 'login'), 'log-out' );
    <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown">My Account</a>
        <ul class="dropdown-menu">
            <li><a href="<?= $uri; ?>">Logout</a></li>
            <li><a href="<?= get_permalink(x); ?>">Edit Account</a></li>
<?php else : ?>
    <li class="login-button">
        <a class="btn-lg" href="<?= get_permalink(x); ?>">Member Login</a>
<?php endif; ?>

However, with page caching enabled this has all sorts of problems.

I was looking at the Fragment Caching notes in W3TC's FAQ section but it looks like it has a major failing - it says:

Be aware that WordPress functions will not be available.

So, if I understand it correctly, that pretty much stops me from being able to use fragment caching.

As the member login/my account button is ever-present in the site main nav I've just disabled page caching entirely for the time being.

Is the only option for me to integrate some form of AJAX approach for handling dynamic sections dependent on auth/guest status?

share|improve this question

closed as off-topic by Johannes Pille, gmazzap, ialocin, shea, Pieter Goosen Aug 22 '14 at 4:22

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Johannes Pille, gmazzap, ialocin, shea, Pieter Goosen
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

This is a feature. You can try to disable caching for logged in users, but if it is in the main nav this still won't help as according to the settings screen:

Don't cache pages for logged in users

Unauthenticated users may view a cached version of the last authenticated user's view of a given page. Disabling this option is not recommended.

There are also some other questions for that issue that might clear this up further:

Showing as logged in after logout (W3 Total Cache issue)


share|improve this answer
So really I'm looking at needing to use AJAX to handle the various conditional logged in sections? I tried using the "Don't cache pages for logged in users" but I must have misunderstood how it works - I assumed that logged in users just wouldn't see cached content at all, but I guess that's not how it works.. back to the drawing board! – alexleonard Feb 18 '14 at 3:31
Think about it. What you want is that one URL looks different in different situations while caching it to always serve the same content. There is just no way this could work... – kraftner Feb 18 '14 at 9:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.