WP_Customize_Manager::remove_frameless_preview_messenger_channel()

In this article

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

VersionDescription
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.