Last active
December 2, 2023 18:55
-
-
Save softiconic/0d7b961cd3bb5641ab313b2779f12f82 to your computer and use it in GitHub Desktop.
The default language functionality is not functioning as expected with the Polylang plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
replace (comment) this line in wp-content/plugins/polylang/frontend/choose-lang.php file (line 185) | |
$language = $this->options['hide_default'] && ( ( isset( $_SERVER['HTTP_REFERER'] ) && in_array( parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ), $this->links_model->get_hosts() ) ) || ! $this->options['browser'] ) ? | |
$this->model->get_language( $this->options['default_lang'] ) : | |
$this->get_preferred_language(); // sets the language according to browser preference or default language | |
by | |
$language = 'fa'; | |
protected function home_language() { | |
// Test referer in case PLL_COOKIE is set to false. Since WP 3.6.1, wp_get_referer() validates the host which is exactly what we want | |
// Thanks to Ov3rfly http://wordpress.org/support/topic/enhance-feature-when-front-page-is-visited-set-language-according-to-browser | |
$language = $this->options['hide_default'] && ( wp_get_referer() || ! $this->options['browser'] ) ? | |
$this->model->get_language( $this->options['default_lang'] ) : | |
$this->get_preferred_language(); // Sets the language according to browser preference or default language | |
$this->set_language( $language ); | |
} | |
Replace By | |
protected function home_language() { | |
// Test referer in case PLL_COOKIE is set to false. Since WP 3.6.1, wp_get_referer() validates the host which is exactly what we want | |
// Thanks to Ov3rfly http://wordpress.org/support/topic/enhance-feature-when-front-page-is-visited-set-language-according-to-browser | |
//$language = $this->options['hide_default'] && ( wp_get_referer() || ! $this->options['browser'] ) ? | |
//$this->model->get_language( $this->options['default_lang'] ) : | |
//$this->get_preferred_language(); // Sets the language according to browser preference or default language | |
$language = 'pt'; | |
$this->set_language( $language ); | |
} | |
////LANGUAGE - function | |
function custom_polylang_langswitcher() { | |
$output = ''; | |
if ( function_exists( 'pll_the_languages' ) ) { | |
$args = [ | |
'show_flags' => 1, | |
'show_names' => 0, | |
'echo' => 0, | |
]; | |
$output = '<ul class="polylang_langswitcher">'.pll_the_languages( $args ). '</ul>'; | |
} | |
return $output; | |
} | |
add_shortcode( 'polylang_langswitcher', 'custom_polylang_langswitcher' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment