Different Logo for Each Language
Swaps the site logo set in the Customizer for a language-specific image, using the language from WPML, Polylang or the WordPress locale.
Opens WPIDE on
Code
$wpide_logos = array( // Language code or locale => attachment ID.
// 'fr' => 123,
// 'de_DE' => 456,
);
add_filter( 'theme_mod_custom_logo', function ( $logo_id ) use ( $wpide_logos ) {
if ( is_admin() ) {
return $logo_id;
}
$locale = determine_locale();
$code = strtok( $locale, '_' );
if ( defined( 'ICL_LANGUAGE_CODE' ) && ICL_LANGUAGE_CODE ) {
$code = ICL_LANGUAGE_CODE;
} elseif ( function_exists( 'pll_current_language' ) && pll_current_language() ) {
$code = pll_current_language();
}
foreach ( array( $locale, $code ) as $key ) {
if ( ! empty( $wpide_logos[ $key ] ) && wp_attachment_is_image( $wpide_logos[ $key ] ) ) {
return (int) $wpide_logos[ $key ];
}
}
return $logo_id;
} );
Notes
Upload each logo to the Media Library and map language codes (or locales such as fr_FR) to attachment IDs in $wpide_logos.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.