Un motore di ricerca WordPress per sviluppatori e autori di temi



render_block_core_search ›

Dan/a
Deprecaton/a
render_block_core_search ( $attributes )
Parametri:
  • (array) $attributes The block attributes.
    Richiesto:
Ritorna:
  • (string) The search block markup.
Definito a:
Codex:

Dynamically renders the `core/search` block.



Sorgenti

function render_block_core_search( $attributes ) {
	static $instance_id = 0;

	$input_id      = 'wp-block-search__input-' . ++$instance_id;
	$label_markup  = '';
	$button_markup = '';

	if ( ! empty( $attributes['label'] ) ) {
		$label_markup = sprintf(
			'<label for="%s" class="wp-block-search__label">%s</label>',
			$input_id,
			$attributes['label']
		);
	}

	$input_markup = sprintf(
		'<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" />',
		$input_id,
		esc_attr( get_search_query() ),
		esc_attr( $attributes['placeholder'] )
	);

	if ( ! empty( $attributes['buttonText'] ) ) {
		$button_markup = sprintf(
			'<button type="submit" class="wp-block-search__button">%s</button>',
			$attributes['buttonText']
		);
	}

	$class = 'wp-block-search';
	if ( isset( $attributes['className'] ) ) {
		$class .= ' ' . $attributes['className'];
	}

	if ( isset( $attributes['align'] ) ) {
		$class .= ' align' . $attributes['align'];
	}

	return sprintf(
		'<form class="%s" role="search" method="get" action="%s">%s</form>',
		$class,
		esc_url( home_url( '/' ) ),
		$label_markup . $input_markup . $button_markup
	);
}