wp_page_reload_on_back_button_js() WordPress Function

This function reloads the current page when the back button is clicked. This is useful for ensuring that the most up-to-date content is displayed, especially if the page has been updated since the last time it was loaded.

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

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.


Top ↑

Source

File: wp-admin/includes/misc.php

function wp_page_reload_on_back_button_js() {
	?>
	<script>
		if ( typeof performance !== 'undefined' && performance.navigation && performance.navigation.type === 2 ) {
			document.location.reload( true );
		}
	</script>
	<?php
}

Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.