wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



build_dropdown_script_block_core_categories › WordPress Function

Seit5.0.0
Veraltetn/v
build_dropdown_script_block_core_categories ( $dropdown_id )
Parameter:
  • (string) $dropdown_id ID of the dropdown field.
    Erforderlich: Ja
Gibt zurück:
  • (string) Returns the dropdown onChange redirection script.
Definiert in:
Codex:

Generates the inline script for a categories dropdown field.



Quellcode

function build_dropdown_script_block_core_categories( $dropdown_id ) {
	ob_start();

	$exports = array( $dropdown_id, home_url() );
	?>
	<script>
	( ( [ dropdownId, homeUrl ] ) => {
		document.getElementById( dropdownId ).addEventListener( 'change', ( event ) => {
			const dropdown = /** @type {HTMLSelectElement} */ ( event.target );
			if ( dropdown.value && dropdown.value !== '-1' ) {
				const url = new URL( homeUrl );
				url.searchParams.set( dropdown.name, dropdown.value );
				location.href = url.href;
			}
		} );
	} )( <?php echo wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
	</script>
	<?php
	return wp_get_inline_script_tag(
		trim( str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) ) .
		"\n//# sourceURL=" . rawurlencode( __FUNCTION__ )
	);
}