WP_Widget_Search::widget() WordPress Method

The WP_Widget_Search::widget() method allows a search widget to be displayed in a Wordpress sidebar. This method takes two parameters: the first is the search query string, and the second is an array of options. The search widget will then use these parameters to display the search results.

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

Outputs the content for the current Search 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 Search widget instance.


Top ↑

Source

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

	public function widget( $args, $instance ) {
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';

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

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

		// Use active theme search form if it exists.
		get_search_form();

		echo $args['after_widget'];
	}


Top ↑

Changelog

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