Is there an easy way to append a unique ID to the preview URL when the preview button is clicked by a user?

So this: http://example.com/news/1/title/?preview=true

Becomes: http://example.com/news/1/title/?preview=true&v={unique_id}

I ask because our setup caches heavily on the server-side so when updating it takes a while for the changes to show up in the preview. Manually adding a parameter to the end of the URL allows the changes to show up immediately.

I tried searching for a plugin but didn't have any luck. Is there a way to do this by adding a custom function in functions.php?

  • Can you provide some more details ? Like which theme & plugin you are using .. Feb 14 '14 at 20:13

Use the preview_post_link filter to modify the preview URL:

function wpa_preview_link( $preview_link ){
    return $preview_link . '&v=' . uniqid();
add_filter( 'preview_post_link', 'wpa_preview_link' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.