Support » Plugin: Polylang » Not getting each language home page with pll_home_url

  • Resolved miguelcortereal


    I’ve just added a new menu item to wp admin bar with this code:

    function adminbar_visitsite_menu() {
        global $wp_admin_bar, $polylang;
            if ( !is_user_logged_in() ) { return; }
    	if ( is_admin() ) {
        		$wp_admin_bar->add_menu( array(
           			'id' => 'v_site_menu',
            		'title' => __( 'Visit Site', 'tugaok' ),
            		'href' => pll_home_url(), )
    	} else {
    	       $wp_admin_bar->add_menu( array(
           			'id' => 'v_dashboard_menu',
            		'title' => __( 'Control Panel', 'tugaok' ),
            		'href' => admin_url(), )
    add_action( 'admin_bar_menu', 'adminbar_visitsite_menu', 25 );

    The only link I get for ‘href’ => pll_home_url(), is the home page for default language.

    Any thing wrong with my code ?

    I don’t have a static page defined.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chouby


    Nothing wrong but the result is what I expect, since pll_home_url returns the home url in the current language on frontend and default language on admin (as there is no “current language” defined).

    What is your expected result?

    My admin has language defined and translates for all langugages.

    I was expecting the link given by pll_home_url could change according the backend language, but now I understand it doesn’t.

    Being so I’ll replace pll_home_url by a pll registered string and use table strings to have each language home page url.

    Plugin Author Chouby


    The difficulty with backend is that there are two “current language”: the backend language and the admin language filter.

    So if you want the backend language, you can get it using:

    global $polylang;
    $locale = get_locale();
    $language = $polylang->model->get_language($locale);
    $home_url = get_term_link($language->slug, 'language');

    You may need to make a special case for the default language


    Haven’t tried yet the pll_register_string but thinking better I suppose it won’t work eather for the same reason that pll_home_url doesn’t.

    So I’m trying your way.

    Working now according your last tip and I did have to create an if statement.


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Not getting each language home page with pll_home_url’ is closed to new replies.