Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created March 9, 2022 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searchwpgists/0daf065910eb8ec8dc6bda211fc742b9 to your computer and use it in GitHub Desktop.
Save searchwpgists/0daf065910eb8ec8dc6bda211fc742b9 to your computer and use it in GitHub Desktop.
<?php
// @link https://searchwp.com/documentation/knowledge-base/engine-select-dropdown/
// ***** UNCOMMENT THIS IF YOU WANT TO USE SHORTCODES IN WIDGETS
// add_filter( 'widget_text', 'do_shortcode' );
// Output a SearchWP Engines dropdown
function my_searchwp_shortcodes_inject_engines() { ?>
<p class="searchwp-shortcodes-engines">
<?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>
</p><?php
}
add_action( 'searchwp_shortcodes_after_input', 'my_searchwp_shortcodes_inject_engines' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment