Set GeneratePress logos based on Polylang current language
This file contains 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
/** | |
* Set GeneratePress site logo based on Polylang current language | |
* | |
* This example function allows for the default logo to be set by the English choice, and supports | |
* Polish, Dutch and German language-specific logos | |
*/ | |
if ( ! function_exists( 'generate_construct_logo' ) || ! function_exists( 'pll_current_language' ) ) { | |
// Change logo depending on the language | |
// An improvemnt to this would be to not set the array of logos, but check for a logo/language match | |
function mattrad_default_logo( $url ) { | |
$current_lang = pll_current_language(); | |
$assets_url = get_stylesheet_directory_uri() . '/assets/images/'; | |
$url = $assets_url . 'logo-en.png'; | |
if ( $current_lang !== pll_default_language() ) { | |
$logos = [ | |
'pl' => 'logo-pl.png', | |
'nl' => 'logo-nl.png', | |
'de' => 'logo-de.png', | |
]; | |
if ( isset( $logos[ $current_lang ] ) ) { | |
$url = $assets_url . $logos[ $current_lang ]; | |
} | |
} | |
return esc_url( $url ); | |
} | |
add_filter( 'generate_logo', 'mattrad_default_logo' ); | |
// Set the logo's width and height | |
// Otherwise, these are not set unless there's an image set in Customizer | |
function mattrad_default_logo_attrs( $attr ) { | |
$attr['width'] = '212'; | |
$attr['height'] = '150'; | |
return $attr; | |
} | |
add_filter( 'generate_logo_attributes', 'mattrad_default_logo_attrs' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment