wp_iframe() WordPress Function

The wp_iframe() function allows for the inclusion of an iframe within a WordPress page. The function takes two parameters: the URL of the iframe contents, and an array of arguments. The URL is required, while the array of arguments is optional. The function can be used to embed content from another website, such as a video from YouTube, or a form from a third-party service. The function can also be used to display content that is only available on the iframe URL, such as an interactive map. The optional array of arguments can be used to customize the iframe. The array can contain the following keys: - width: The width of the iframe, in pixels. - height: The height of the iframe, in pixels. - class: A CSS class to add to the iframe. - id: A CSS id to add to the iframe. - frameborder: The frameborder attribute. Defaults to 0. - allowfullscreen: Whether to allow the iframe to be displayed in fullscreen mode. Defaults to false. If you're using the wp_iframe() function to embed a video from YouTube, you can use the following code: wp_iframe( 'https://www.youtube.com/embed/VIDEO_ID', array( 'width' =>560, 'height' =>315, 'allowfullscreen' => true, ) );

wp_iframe( callable $content_func, mixed $args ) #

Outputs the iframe to display the media upload page.


Parameters

$content_func

(callable)(Required)Function that outputs the content.

$args

(mixed)(Optional)additional parameters to pass to the callback function when it's called.


Top ↑

Source

File: wp-admin/includes/media.php

function wp_iframe( $content_func, ...$args ) {
	_wp_admin_html_begin();
	?>
	<title><?php bloginfo( 'name' ); ?> &rsaquo; <?php _e( 'Uploads' ); ?> &#8212; <?php _e( 'WordPress' ); ?></title>
	<?php

	wp_enqueue_style( 'colors' );
	// Check callback name for 'media'.
	if (
		( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) ||
		( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) )
	) {
		wp_enqueue_style( 'deprecated-media' );
	}

	?>
	<script type="text/javascript">
	addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
	var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
	isRtl = <?php echo (int) is_rtl(); ?>;
	</script>
	<?php
	/** This action is documented in wp-admin/admin-header.php */
	do_action( 'admin_enqueue_scripts', 'media-upload-popup' );

	/**
	 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.
	 *
	 * @since 2.9.0
	 */
	do_action( 'admin_print_styles-media-upload-popup' );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

	/** This action is documented in wp-admin/admin-header.php */
	do_action( 'admin_print_styles' );

	/**
	 * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed.
	 *
	 * @since 2.9.0
	 */
	do_action( 'admin_print_scripts-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

	/** This action is documented in wp-admin/admin-header.php */
	do_action( 'admin_print_scripts' );

	/**
	 * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0)
	 * media upload popup are printed.
	 *
	 * @since 2.9.0
	 */
	do_action( 'admin_head-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

	/** This action is documented in wp-admin/admin-header.php */
	do_action( 'admin_head' );

	if ( is_string( $content_func ) ) {
		/**
		 * Fires in the admin header for each specific form tab in the legacy
		 * (pre-3.5.0) media upload popup.
		 *
		 * The dynamic portion of the hook name, `$content_func`, refers to the form
		 * callback for the media upload type.
		 *
		 * @since 2.5.0
		 */
		do_action( "admin_head_{$content_func}" );
	}

	$body_id_attr = '';

	if ( isset( $GLOBALS['body_id'] ) ) {
		$body_id_attr = ' id="' . $GLOBALS['body_id'] . '"';
	}

	?>
	</head>
	<body<?php echo $body_id_attr; ?> class="wp-core-ui no-js">
	<script type="text/javascript">
	document.body.className = document.body.className.replace('no-js', 'js');
	</script>
	<?php

	call_user_func_array( $content_func, $args );

	/** This action is documented in wp-admin/admin-footer.php */
	do_action( 'admin_print_footer_scripts' );

	?>
	<script type="text/javascript">if(typeof wpOnload==='function')wpOnload();</script>
	</body>
	</html>
	<?php
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.0Formalized the existing and already documented ...$args parameter by adding it to the function signature.
2.5.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.

Show More