Site logo

Archived topic

Logo url translation

5 replies · Started by Ketil on March 3, 2021

Viewing posts 1–6 of 6

Hello,
How can I make the logo follow the translation, I get the root url from all languages without the "/en" addition for english etc.

Hi Ketil,

Give this php snippet a try:

add_filter( 'generate_logo_href', function() {
    $currentlang = get_bloginfo('language');
    if($currentlang=="en-US"){
        return "your-custom-url";
    }
} );

Adding PHP: https://docs.generatepress.com/article/adding-php/

Hi. Will the snippet code work with a relative link, and will I have to edit it when I add more languages to the site?

As long as the page's language is en-US, it will work.

If you add more language, you'll need to edit the snippet a bit.

Hi. Some problem has occured to the translation code for logo, it seems for norwegian translation the logo links to page itself instead of to the root. Works in English.

Hi there,

Let's modify Ying's code a bit.

The issue here is: The filter doesn't return href value for anything else.

That said, We should make one.

add_filter( 'generate_logo_href', function() {
    $currentlang = get_bloginfo('language');
    if($currentlang=="en-US"){
        return "your-custom-url";
    } else {
        return home_url( '/' );
    }
} );

The else statement is the default state. The other if() statements are for your specific languages.

This archived topic is closed to new replies.