admin管理员组文章数量:1406217
As per the title, how would you change the search url for different sites in a multisite network. eg:
testsite.co.uk/search
testsite.de/suchen
testsite.fr/recherche
I can change the search term for one, and all, sites using:
function change_search_url_rewrite() {
if ( is_search() && isset($_GET['s']) ) {
$str = get_query_var( 's' );
$str = sanitize_text_field($str);
//replace slash with html entity
$str = str_replace('/', '∕', $str);
$str = preg_replace('/\s+/', ' ', $str );
if(empty($str)){
$str = " ";
}
wp_redirect( home_url( "/search/" ) . urlencode( $str ) );
exit();
}
}
add_action( 'template_redirect', 'change_search_url_rewrite',1 );
Having the search term change on a per site basis does not work though.
Through the use of an option field in a mu plugin, I couldnt get the term to conditionally change, as per:
function change_search_url_rewrite() {
if ( is_search() && isset($_GET['s']) ) {
$option = get_option('test_options');
// get theme option
$locstr = $option['test_o_locale'];
if($locstr === 'fr'){
$strurl = "recherche";
}elseif($locstr === 'de'){
$strurl = "suchen";
}else{
$strurl = "search";
}
$str = get_query_var( 's' );
$str = sanitize_text_field($str);
//replace slash with html entity
$str = str_replace('/', '∕', $str);
$str = preg_replace('/\s+/', ' ', $str );
if(empty($str)){
$str = " ";
}
wp_redirect( home_url( "/".$strurl."/" ) . urlencode( $str ) );
exit();
}
}
add_action( 'template_redirect', 'change_search_url_rewrite',1 );
The function does work and changes the sites url as per the logic, but they return 404s.
Could anyone please advise, I am assuming I need to address this through htaccesss? But not 100% sure if that would be the right way to go.
Any help appreciated, cheers.
本文标签: htaccessChange Search url slug for each site in a multisite network
版权声明:本文标题:htaccess - Change Search url slug for each site in a multisite network 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744987302a2636167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论