WP_Widget_Media::widget() WordPress Method

The WP_Widget_Media::widget() method is used to display media objects on a WordPress site. This method accepts two arguments: an array of media objects and a boolean value specifying whether to display the media objects in a gallery format. The media objects can be images, videos, or audio files. The method returns a string containing the HTML markup for the media objects.

WP_Widget_Media::widget( array $args, array $instance ) #

Displays the widget on the front-end.


Description

Top ↑

See also


Top ↑

Parameters

$args

(array)(Required)Display arguments including before_title, after_title, before_widget, and after_widget.

$instance

(array)(Required)Saved setting from the database.


Top ↑

Source

File: wp-includes/widgets/class-wp-widget-media.php

	public function widget( $args, $instance ) {
		$instance = wp_parse_args( $instance, wp_list_pluck( $this->get_instance_schema(), 'default' ) );

		// Short-circuit if no media is selected.
		if ( ! $this->has_content( $instance ) ) {
			return;
		}

		echo $args['before_widget'];

		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
		$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );

		if ( $title ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}

		/**
		 * Filters the media widget instance prior to rendering the media.
		 *
		 * @since 4.8.0
		 *
		 * @param array           $instance Instance data.
		 * @param array           $args     Widget args.
		 * @param WP_Widget_Media $widget   Widget object.
		 */
		$instance = apply_filters( "widget_{$this->id_base}_instance", $instance, $args, $this );

		$this->render_media( $instance );

		echo $args['after_widget'];
	}


Top ↑

Changelog

Changelog
VersionDescription
4.8.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.