wp_page_reload_on_back_button_js

Outputs JS that reloads the page if the user navigated to it with the Back or Forward button.

Description

wp_page_reload_on_back_button_js(); 

Used on the Edit Post and Add New Post screens. Needed to ensure the page is not loaded from browser cache, so the post title and editor content are the last saved versions. Ideally this script should run first in the head.


Usage

  1. if ( !function_exists( 'wp_page_reload_on_back_button_js' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_page_reload_on_back_button_js(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/misc.php  
  1. function wp_page_reload_on_back_button_js() { 
  2. ?> 
  3. <script> 
  4. if ( typeof performance !== 'undefined' && performance.navigation && performance.navigation.type === 2 ) { 
  5. document.location.reload( true ); 
  6. </script> 
  7. <?php