-
-
Save searchwpgists/fd4e1ef6befb4c50ba6ffa0368332cf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Adds a SearchWP Engines dropdown to the search form | |
// @link https://searchwp.com/documentation/knowledge-base/engine-select-dropdown/ | |
function my_searchwp_get_search_form_with_engines_dropdown( $form ) { | |
ob_start(); ?> | |
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> | |
<label> | |
<span class="screen-reader-text">Search For</span> | |
<input type="search" class="search-field" placeholder="Search..." value="<?php echo esc_attr( get_search_query() ); ?>" name="s" title="Search for:" /> | |
</label> | |
<?php | |
$engines = \SearchWP\Settings::get_engines(); | |
$current_engine = isset( $_GET['swpengine'] ) ? esc_attr( $_GET['swpengine'] ) : 'default'; | |
?> | |
<select name="swpengine" id="swpengine"> | |
<?php foreach ( $engines as $engine_name => $engine ) : ?> | |
<option value="<?php echo esc_attr( $engine_name ); ?>" | |
<?php selected( $current_engine, $engine_name ); ?>> | |
<?php echo esc_html( $engine->get_label() ); ?> | |
</option> | |
<?php endforeach; ?> | |
</select> | |
<input type="submit" class="search-submit" value="Search" /> | |
</form> | |
<?php return ob_get_clean(); | |
} | |
add_filter( 'get_search_form', 'my_searchwp_get_search_form_with_engines_dropdown' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment