Exclude the search page
If you would like to exclude the search page from being translated, you can use the following code:
1
<?php
2
3
add_action( 'pre_get_posts', 'custom_weglot_translated_search_redirect' );
4
function custom_weglot_translated_search_redirect() {
5
if ( ! function_exists( 'weglot_get_original_language' ) || ! function_exists( 'weglot_get_current_language' ) ) {
6
return;
7
}
8
if ( is_search() && ! is_admin() && weglot_get_original_language() != weglot_get_current_language() ) {
9
wp_redirect( weglot_get_full_url_no_language(), 301 );
10
exit;
11
}
12
}
13
14
add_filter( 'weglot_button_html', 'custom_weglot_translated_search_no_selector' );
15
function custom_weglot_translated_search_no_selector( $button_html ) {
16
if ( is_search() && ! is_admin() ) {
17
return '';
18
}
19
return $button_html;
20
}
Copied!
Last modified 1yr ago
Copy link