pll_preferred_language

Filter the visitor's preferred language (normally set first by cookie if this is not the first visit, then by the browser preferences).

Description

apply_filters( 'pll_preferred_language', (bool) $this_get_preferred_browser_language ); 

If no preferred language has been found or set by this filter, Polylang fallbacks to the default language

Parameters (1)

0. $this_get_preferred_browser_language (bool)
The this options browser this get preferred browser language false.

Usage

To run the hook, copy the example below.
  1. $this_get_preferred_browser_language = apply_filters( 'pll_preferred_language', $this_get_preferred_browser_language ); 
  2.  
  3. if ( !empty( $this_get_preferred_browser_language ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the pll_preferred_language callback 
  2. function filter_pll_preferred_language( $this_get_preferred_browser_language ) { 
  3. // make filter magic happen here... 
  4. return $this_get_preferred_browser_language
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'pll_preferred_language', 'filter_pll_preferred_language', 10, 1 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'pll_preferred_language', 'filter_pll_preferred_language', 10, 1 ); 

Defined (1)

The filter is defined in the following location(s).

/frontend/choose-lang.php  
  1. $slug = apply_filters( 'pll_preferred_language', $this->options['browser'] ? $this->get_preferred_browser_language() : false );