WP_Widget_Block::widget() WordPress Method

The WP_Widget_Block::widget() method allows you to display a WordPress widget in a block. This method takes two parameters: the widget ID and the widget name. The widget ID is the unique identifier for the widget, and the widget name is the name of the widget.

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

Outputs the content for the current Block widget instance.


Parameters

$args

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

$instance

(array)(Required)Settings for the current Block widget instance.


Top ↑

Source

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

	public function widget( $args, $instance ) {
		$instance = wp_parse_args( $instance, $this->default_instance );

		echo str_replace(
			'widget_block',
			$this->get_dynamic_classname( $instance['content'] ),
			$args['before_widget']
		);

		/**
		 * Filters the content of the Block widget before output.
		 *
		 * @since 5.8.0
		 *
		 * @param string          $content  The widget content.
		 * @param array           $instance Array of settings for the current widget.
		 * @param WP_Widget_Block $widget   Current Block widget instance.
		 */
		echo apply_filters(
			'widget_block_content',
			$instance['content'],
			$instance,
			$this
		);

		echo $args['after_widget'];
	}


Top ↑

Changelog

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