Breadcrumb “HOME” string does not work with Polylang

#182059
  • Resolved RwkY
    Rank Math free

    Hi there,

    I have a website with 3 languages, and I use the RankMath breadcrumbs; for the translation I’m using polylang.

    Issue is that the home label (breadcrumbs_home_label) is translated but not reflected in front-end:

Viewing 5 replies - 1 through 5 (of 5 total)
  • Anas
    Rank Math business

    Hello,

    Thank you for contacting Rank Math, and sorry for any inconvenience caused.

    Please add the following filter to your theme’s functions.php to make the change to the homepage link:

    
    /**
     * 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);
    

    Let us know if this code fixes the issue.

    ​​​​​​​Don’t hesitate to get in touch if you require any further assistance.

    RwkY
    Rank Math free

    Hi there, it fixed another issue I did not notice, the link, now it links properly to homepage in the language is viewed, but the displayed text is still wrong.

    Anas
    Rank Math business

    Hello,

    Please try this code.

    /**
     * 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;
    	$crumbs[0][0] = pll__("Home");
    
    return $crumbs;
    }, 10, 2);

    I hope this helps. Looking forward to helping you.

    RwkY
    Rank Math free

    yes and no, it says “home” for all languages, I can’t translate it.

    LE: now it works o.O just did another reload of the page and it translates properly + links properly. thank you!

    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 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this ticket.