Skip to content

Instantly share code, notes, and snippets.

@bramchi bramchi/searchform.php
Last active Mar 6, 2019

Embed
What would you like to do?
Roots.io searchform.php template hack to get search widget working in Polylang, only searching within the active language. 'soil-nice-search' disabled btw.
<?php
/*
*
* Roots.io searchform.php template hack to fix Polylang search
*
* Note: Polylang setting 'Hide URL language info for default language' should be enabled for this to work.
* Soil-nice-search disabled in Roots.
*
*/
if(function_exists('pll_current_language')){
$current_language = pll_current_language();
$default_language = pll_default_language();
if($current_language != $default_language){
$language_subdir = $current_language.'/';
} else {
$language_subdir = '';
}
}
?>
<form role="search" method="get" class="search-form form-inline" action="<?php echo esc_url(home_url('/'.$language_subdir)); ?>">
<label class="sr-only"><?php _e('Search for:', 'roots'); ?></label>
<div class="input-group">
<input type="search" value="<?php echo get_search_query(); ?>" name="s" class="search-field form-control" placeholder="<?php _e('Search', 'roots'); ?> <?php bloginfo('name'); ?>">
<span class="input-group-btn">
<button type="submit" class="search-submit btn btn-default"><?php _e('Search', 'roots'); ?></button>
</span>
</div>
</form>
@rwkyyy

This comment has been minimized.

Copy link

commented May 2, 2018

Thank you!

@AlainMelsens

This comment has been minimized.

Copy link

commented Mar 6, 2019

Just great! Even after many years, it's working!
This should be integrated somewhere as a standard option in Polylang. :)
Thank you so much for this helpfully hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.