Skip to content

Instantly share code, notes, and snippets.

@isaumya
Created December 23, 2016 12:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaumya/424c52f7b0da474c0f906dd5d770edb0 to your computer and use it in GitHub Desktop.
Save isaumya/424c52f7b0da474c0f906dd5d770edb0 to your computer and use it in GitHub Desktop.
Refresh page when click browser back button
<?php
/**
* Adding a special function to ensure that when the user click on back button,
* it will reload the pages, instead of loading from cache so that the js can run again
**/
add_action( 'wp_footer', 'aicp_refresh_on_back' );
function aicp_refresh_on_back() {
echo '<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
var e=document.getElementById("refreshed");
if(e.value=="no")e.value="yes";
else{e.value="no";location.reload();}
}
</script>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment