wpseek.com
A WordPress-centric search engine for devs and theme authors



build_dropdown_script_block_core_categories › WordPress Function

Since5.0.0
Deprecatedn/a
build_dropdown_script_block_core_categories ( $dropdown_id )
Parameters:
  • (string) $dropdown_id ID of the dropdown field.
    Required: Yes
Returns:
  • (string) Returns the dropdown onChange redirection script.
Defined at:
Codex:

Generates the inline script for a categories dropdown field.



Source

function build_dropdown_script_block_core_categories( $dropdown_id ) {
	ob_start();
	?>
	<script>
	( function() {
		var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' );
		function onCatChange() {
			if ( dropdown.options[ dropdown.selectedIndex ].value !== -1 ) {
				location.href = "<?php echo esc_url( home_url() ); ?>/?" + dropdown.name + '=' + dropdown.options[ dropdown.selectedIndex ].value;
			}
		}
		dropdown.onchange = onCatChange;
	})();
	</script>
	<?php
	return wp_get_inline_script_tag( str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) );
}