title: Can I have dynamic content in a WP page cached by WP Super Cache?
body: <p>Trying to implement the technique discussed here,</p>
  
  <p><a href="http://z9.io/2013/10/21/shiny-new-dynamic-content-wp-super-cache/" rel="nofollow">http://z9.io/2013/10/21/shiny-new-dynamic-content-wp-super-cache/</a></p>
  
  <p>into a site that is using the Genesis framework.  I was wondering if anybody has made this technique work at all, but more so interested if anybody has made it work using Genesis.</p>
  
  <p>Here is my code for anybody interested:</p>
  
  <p>First, the page template file (test-age.php):</p>
  
  <pre><code>&lt;?php
  
  /*
   * Template Name: Test Template
   */
  
  remove_action( 'genesis_loop', 'genesis_do_loop' );
  remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  add_action( 'genesis_loop', 'support_loop' );
  
  // Content Area
  
  define( 'DYNAMIC_OUTPUT_BUFFER_TAG', 'moonshine' ); // Change this to a secret placeholder tag
  
  if ( DYNAMIC_OUTPUT_BUFFER_TAG != '' ) {
      function dynamic_output_buffer_test( &amp;$cachedata = 0 ) {
          if ( defined( 'DYNAMIC_OB_TEXT' ) )
              return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
          ob_start();
          // call the sidebar function, do something dynamic
          include( 'test-content.php' );
          $text = ob_get_contents();
          ob_end_clean();
          if ( $cachedata === 0 ) { // called directly from the theme so store the output
              define( 'DYNAMIC_OB_TEXT', $text );
          } else // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php
              return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
      }
      add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
      function dynamic_output_buffer_init() {
          add_action( 'wp_footer', 'dynamic_output_buffer_test' );
      }
      add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
      function dynamic_output_buffer_test_safety( $safety ) {
          if ( defined( 'DYNAMIC_OB_TEXT' ) ) // this is set when you call dynamic_output_buffer_test() from the theme
              return 1; // ready to replace tag with dynamic content.
          else
              return 0; // tag cannot be replaced.
      }
      add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
  }
  
  function support_loop() {
      echo "\n"; // make source views more pleasant for debugging
      ?&gt;
      &lt;div class="test-page"&gt;
          &lt;?php
          if ( function_exists( 'dynamic_output_buffer_test' ) )
              dynamic_output_buffer_test();
          ?&gt;moonshine&lt;?php
      ?&gt;
      &lt;/div&gt;
      &lt;?php
      echo "\n"; // make source views more pleasant for debugging
  }
  
  genesis();
  ?&gt;
  </code></pre>
  
  <p>And the file that contains the would produce the dynamic content (test-content.php):</p>
  
  <pre><code>&lt;?php
  echo "The test was successful!!!!";
  ?&gt;
  </code></pre>
  
  <p>Any thoughts or insights would be appreciated.</p>
  
  <p>PS- I can turn caching off for an entire page, that is easy. However, I looking to have cached pages where certain sections are still dynamically generated. I could also do this via javascript on the client-side, but that would mean rewriting other plugins and widgets we have written and that is not an option at this point.  I have also verified that all WP Super Cache settings are correct for the technique (php caching selected, late init true, dynamic caching true).</p>