wp_post_preview_js
Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
Description
wp_post_preview_js();
This prevents reusing the same tab for a preview when the user has navigated away.
Usage
if ( !function_exists( 'wp_post_preview_js' ) ) { require_once ABSPATH . WPINC . '/functions.php'; } // NOTICE! Understand what this does before running. $result = wp_post_preview_js();
Defined (1)
The function is defined in the following location(s).
- /wp-includes/functions.php
- function wp_post_preview_js() {
- global $post;
- if ( ! is_preview() || empty( $post ) ) {
- return;
- }
- // Has to match the window name used in post_submit_meta_box()
- $name = 'wp-preview-' . (int) $post->ID;
- ?>
- <script>
- ( function() {
- var query = document.location.search;
- if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
- window.name = '<?php echo $name; ?>';
- }
- if ( window.addEventListener ) {
- window.addEventListener( 'unload', function() { window.name = ''; }, false );
- }
- }());
- </script>
- <?php