Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WP_REST_Widget_Types_Controller::render_legacy_widget_preview_iframe( string $id_base, array $instance ): string

Renders a page containing a preview of the requested Legacy Widget block.


$id_base string Required
The id base of the requested widget.
$instance array Required
The widget instance attributes.

Top ↑


string Rendered Legacy Widget block preview.

Top ↑


File: wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php. View all references

private function render_legacy_widget_preview_iframe( $id_base, $instance ) {
	if ( ! defined( 'IFRAME_REQUEST' ) ) {
		define( 'IFRAME_REQUEST', true );

	<!doctype html>
	<html <?php language_attributes(); ?>>
		<meta charset="<?php bloginfo( 'charset' ); ?>" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<link rel="profile" href="" />
		<?php wp_head(); ?>
			/* Reset theme styles */
			html, body, #page, #content {
				padding: 0 !important;
				margin: 0 !important;
	<body <?php body_class(); ?>>
	<div id="page" class="site">
		<div id="content" class="site-content">
			$registry = WP_Block_Type_Registry::get_instance();
			$block    = $registry->get_registered( 'core/legacy-widget' );
			echo $block->render(
					'idBase'   => $id_base,
					'instance' => $instance,
		</div><!-- #content -->
	</div><!-- #page -->
	<?php wp_footer(); ?>
	return ob_get_clean();

Top ↑


Version Description
5.9.0 Introduced.

Top ↑

User Contributed Notes

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