W3cubDocs

/WordPress

WP_Customize_Manager::remove_frameless_preview_messenger_channel()

Removes customize_messenger_channel query parameter from the preview window when it is not in an iframe.

Description

This ensures that the admin bar will be shown. It also ensures that link navigation will work as expected since the parent frame is not being sent the URL to navigate to.

Source

public function remove_frameless_preview_messenger_channel() {
	if ( ! $this->messenger_channel ) {
		return;
	}
	ob_start();
	?>
	<script>
	( function() {
		if ( parent !== window ) {
			return;
		}
		const url = new URL( location.href );
		if ( url.searchParams.has( 'customize_messenger_channel' ) ) {
			url.searchParams.delete( 'customize_messenger_channel' );
			location.replace( url );
		}
	} )();
	</script>
	<?php
	wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
}

Changelog

Version Description
4.7.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_manager/remove_frameless_preview_messenger_channel