WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP Super Cache] Half on & sidebars (8 posts)

  1. saharusa
    Member
    Posted 4 years ago #

    When using mfunc to exclude sidebar from being cached like this:

    <!--mfunc get_sidebar('right') -->
    <?php get_sidebar('right'); ?>
    <!--/mfunc-->

    the sidebar stay dynamic but condition within widgets won't work anymore, for example:

    function widget() {
       if(is_single()) {
         echo 'widget on single page';
       }
    }

    Nothing is printed on single...

    Is it known bug ? or I'm doing something wrong here ?

  2. Donncha O Caoimh
    Member
    Posted 4 years ago #

    That's a side effect of how the mfunc system works - WordPress hasn't set up the is_single() settings when it serves the cache.

    You could try the late init configuration. See the developer docs.

  3. saharusa
    Member
    Posted 4 years ago #

    Tried that... not working also with late init... basically none of wp condition is working within a widget.

  4. saharusa
    Member
    Posted 4 years ago #

    I must say that's a really sad side effect :(
    It's like having a dynamic support along side serving from cache but
    without all the advantage of wordpress.

    Is there any way to work around it you think of ? maybe including some wp core files if serves from cache ?

  5. Donncha O Caoimh
    Member
    Posted 4 years ago #

    You could possibly examine the REQUEST_URI and manually figure out if you're on a single page or not.

    I presume the single page check only works in "the loop" where posts are printed. The widget code is executed long before that when it's cached.

  6. saharusa
    Member
    Posted 4 years ago #

    I can check if single.. the thing is, I'm not talking about checking only if single or not, I'm talking about every wp condition tags, for example, check if is category, can't know that based on url (using permalink without 'category' prefix) unless I do some really crazy-non-logic db queries.

  7. Donncha O Caoimh
    Member
    Posted 4 years ago #

    Yeah, it's a side effect of caching - you cache to reduce the load on your server and that means not doing as much processing and loading as much, but you have to sacrifice some functionality when a page is cached. (or do it another way, perhaps by loading the widget using Javascript)

  8. saharusa
    Member
    Posted 4 years ago #

    Thanks,I returned to 'on' mode :) set it to 10 min caching, site is super fast, important widgets loads via js (banners etc..)

Topic Closed

This topic has been closed to new replies.

About this Topic