Trying to understand dynamic cacheaction filter…
-
Ok, I’m trying to work out having some dynamic content with the rest of the page cached.
I’m looking at the examples from:
https://z9.io/2013/10/21/shiny-new-dynamic-content-wp-super-cache/
https://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.phpI’m using the first example script exactly as it is on the example page, with the exception of adding ‘testtest’ as the tag. (did I do that correctly?)
Here’s what I’ve got
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
----------------------------- define( 'DYNAMIC_CACHE_TEST_TAG', 'testtest' ); // 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_output_buffer_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' ); } -----------------------------------
I pasted it into single.php (inside php tags) just after my post content is generated. I clear the cache, view the source code… but nothing shows up from this script.
In the instructions it says I need to include the tag in the theme.
So I add (outside of php tags) “testtest” under the script.
At that point I should get the “<!– Hello world at…” in the source code, correct?
I don’t get anything but “testtest” there.
I tried putting the script into my functions.php and that didn’t make a difference. I wasn’t sure where it was supposed to go, on single.php or functions.php (or somewhere else?)
I deleted the cache each time I tested.
I tried doing this:
--------- if ( function_exists( 'dynamic_cache_test_filter' ) ) { dynamic_output_buffer_test(); ?>testtest<?php } ---------
and the ‘testtest’ disappeared but was not replaced. Does that mean the script isn’t working?
On my WP Super Cache advanced settings, I have ‘Use PHP’, ‘Enable Dynamic Cacheing’, and ‘Late Init’ enabled.
Where am I going wrong?
Thanks for any help!
Chris
- The topic ‘Trying to understand dynamic cacheaction filter…’ is closed to new replies.