WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Not getting each language home page with pll_home_url (6 posts)

  1. miguelcortereal
    Member
    Posted 9 months ago #

    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.

    http://wordpress.org/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 9 months ago #

    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?

  3. miguelcortereal
    Member
    Posted 9 months ago #

    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.

  4. Chouby
    Member
    Plugin Author

    Posted 9 months ago #

    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

  5. miguelcortereal
    Member
    Posted 9 months ago #

    Thanks.

    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.

  6. miguelcortereal
    Member
    Posted 9 months ago #

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

    Thanks

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.