V
V
Vasily Petrov2017-05-21 22:34:09
caching
Vasily Petrov, 2017-05-21 22:34:09

How to disable caching for some objects in wordpress (WP Super Cache)?

How to disable caching in WP Super Cache plugin for some objects like div with no-cache class? Or is it better to use another plugin? Or even without plugins?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2017-05-21
@mbpig

More or less like this:

define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // Change this to a secret placeholder tag
if ( DYNAMIC_CACHE_TEST_TAG != '' ) {
  function dynamic_cache_test_safety( $safety ) {
    return 1;
  }
  add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );
  function dynamic_cache_test_filter( &$cachedata) {
    return str_replace( DYNAMIC_CACHE_TEST_TAG, "<!-- Hello world at " . date( 'H:i:s' ) . " -->", $cachedata );
  }
  add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
  function dynamic_cache_test_template_tag() {
    echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag
  }
  function dynamic_cache_test_init() {
    add_action( 'wp_footer', 'dynamic_cache_test_template_tag' );
  }
  add_cacheaction( 'add_cacheaction', 'dynamic_cache_test_init' );
}

You set your DYNAMIC_CACHE_TEST_TAG, insert it at the right place in the template, respectively, the plugin will cache the page along with the value of the DYNAMIC_CACHE_TEST_TAG constant, and then use the wpsc_cachedata hook to replace it with the output of your function.
More examples and details here .
PS And there it seemed like it was necessary to play around with the checkboxes in the plugin settings, late initialization felts or something like that. It seems to be written about it on the plugin settings page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question