Skip to content

Instantly share code, notes, and snippets.

@mattradford
Last active June 19, 2022 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattradford/111f0c15e075fbab810a5abca3d74e6a to your computer and use it in GitHub Desktop.
Save mattradford/111f0c15e075fbab810a5abca3d74e6a to your computer and use it in GitHub Desktop.
Set GeneratePress logos based on Polylang current language
/**
* 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