Breadcrumbs homepage link different languages

#59971
Viewing 7 replies - 1 through 7 (of 7 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    You might use some custom PHP code using our filters. If you let me know which plugin are you using for multiple languages, I can try to give you a code snippet to make it work.

    This should be the base code where we should do that modification:

    /**
     * Allow changing or removing the Breadcrumb items
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	return $crumbs;
    }, 10, 2);

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hey Alberto,
    thanks for the answer.

    I am using polylang.

    Appreciate if you can send me the code snippet.

    Just to make it clear, need two different “Homepage Links”
    One for the german site and one for the english.

    Thanks once again.

    Alberto
    Rank Math business

    Hello,

    I have done the custom snippet for you, it should support any language added with Polylang:

    /**
     * Change the Home URL in breadcrumbs according to the current language in Polylang
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    
            // With this code, we get the home URL with the current language
            $home_link = pll_home_url(pll_current_language());
            
            // The first item in the $crumbs array is usually the home (except if it is disabled
            // The second item inside each item is the link (so in this case, the home link)
            $crumbs[0][1] = $home_link;
    
    	return $crumbs;
    }, 10, 2);

    Looking forward to help you.

    appreciate alberto it works.

    thank you so much 😉

    Hello,

    We are glad you were able to resolve your issue.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Thanks, the code also worked for me

    Michael Davis
    Rank Math pro

    Hello,

    Glad that helped.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘Breadcrumbs homepage link different languages’ is closed to new replies.