Solved: Links in displayed text that break unwanted browser caching

Problem: On a WP server configured for browser caching, I have a “Gateway Page” that renders an HTML field with two different sets of links depending if the visitor is logged in or not.

The page has three fields :

  1. A Single Line Text field defaulted with: {user:user_login}
  2. Two HTML fields called “Known User” and “Unknown User”

The “Enable Conditional Logic” for the two HTML fields either DOES or DOES NOT show the content depending on the value of the Single Line Text field.

This allows the Gateway Page to direct the visitor accordingly to their status.

The only problem I ran into, was the pages of the links in the rendered HTML blocks would be cached by the browser when clicked. I tried several ideas, like appending a query string argument using the date merge tag, but that only made it unique across days, not in the same day…

Solution:
To fix this, I added the code snippet below to functions.php, and coded the links like this:
<A HREF="https://yoyo.com/gateway-form-page/?date={time_unix}">click here</A>

This causes the browser to break cache because the query string makes it unique down to one second granularity.

I hope this helps somebody someday :slight_smile:


Add to bottom of functions.php :

add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
$merge_tag = '{time_unix}';

if ( strpos( $text, $merge_tag ) === false ) {
    return $text;
}

return str_replace( $merge_tag, time(), $text );
}, 10, 7 );

Thank you for sharing that!