Exclude the search page

If you would like to exclude the search page from being translated, you can use the following code:

<?php

add_action( 'pre_get_posts', 'custom_weglot_translated_search_redirect' );
function custom_weglot_translated_search_redirect() {
	if ( ! function_exists( 'weglot_get_original_language' ) || ! function_exists( 'weglot_get_current_language' ) ) {
		return;
	}
	if ( is_search() && ! is_admin() && weglot_get_original_language() != weglot_get_current_language() ) {
		wp_redirect( weglot_get_full_url_no_language(), 301 );
		exit;
	}
}

add_filter( 'weglot_button_html', 'custom_weglot_translated_search_no_selector' );
function custom_weglot_translated_search_no_selector( $button_html ) {
	if ( is_search() && ! is_admin() ) {
		return '';
	}
	return $button_html;
}

Last updated