Hi, Amit here, I am the WPML Support Manager, our current ticket queue is quite calm and I'd like to encourage you to use our new chat support option

We are working hard to debug and look at every single report

All of the known issues are documented in https://wpml.org/known-issues/ you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

We are also adding once a week a tutorial to our YouTube channel - https://www.youtube.com/c/WPML-multilingual - check out if we already covered what you need and leave us a comment if you want us to produce anything there

If you do need to open a ticket please make sure to provide us with all the needed information as described here https://wpml.org/faq/checklist-before-opening-a-ticket-in-wpml-support/

We are very proud at our level of support, we are one team from all over the world and we are all experienced WordPress developers, you can read more about us here - https://wpml.org/forums/supporters/

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 8 replies, has 4 voices.

Last updated by Jan 5 years, 2 months ago.

Assigned support staff: Bruno.

Author Posts
November 13, 2013 at 6:33 pm #291929

PeterS1

Hi,
please add a filter to the head_langs() function. Right now the function uses following code

    function head_langs(){
        $languages = $this->get_ls_languages(array('skip_missing' => true));
        foreach($languages as $code => $lang){
            if($code != $this->get_current_language()){
                printf('<link rel="alternate" hreflang="%s" href="%s" />' . PHP_EOL, $this->get_language_tag($code), str_replace('&', '&', $lang['url']));
            }
        }
    }

to generate the output but it breaks if the theme uses a custom query for the translated entry on the front page (because it returns the permalink of the translated entry and not the blog/homepage url).

Please add a filter to the $languages array which enables the theme author to replace the url with another url if required. For more details see:

hidden link

Thank you,
Peter

November 13, 2013 at 6:48 pm #291940

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Peter,

Thanks for the suggestion. I'll send it to our developers.

Regards

November 14, 2013 at 1:23 pm #292453

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Dear Peter,

I reported this to our developer and he would like a little more information:

-----
Andrea Sciamanna:

I've read the forum ticket, but I don't understand how he's getting the wrong URL.

Could you please get some more details, like an URL to see or at least the URL and what he expect to head_langs to produce?
-----

Thank you.

November 14, 2013 at 1:33 pm #292464

Andrea
Supporter

HI Peter,

There is no need to add a filter in head_langs.

If you want to change or even remove this, you can simply use this code in your theme or plugins:

            global $sitepress, $sitepress_settings;
            if($sitepress_settings['seo']['head_langs']){
                remove_action('wp_head', array($sitepress, 'head_langs'));
                //Uncomment the following line if ypou want to use a custom function
                //add_action('wp_head', array($this, 'my_own_head_langs'));
            }

Hope this helps.

November 15, 2013 at 11:35 am #293001

PeterS1

The problem is that our theme allows the user to set another page as front page (independently of the Settings > Reading option). This however can result in a weird $lang['url'] output if the homepage entry is connected to another translated entry. A theme users describes the issue here: hidden link

If a page (called "Homepage") is used as the "front page" the url in the language switcher links to hidden link and hidden link although the language switcher on the front page should just link to the website/blog main url (= bloginfo('url') output ).

I think the reason is that the language switcher and the head_langs function don't check with is_home() or is_front_page() if the current page is the front page or not but both functions just return the permalink of the translated entry. I mean that's fine for all other pages but in this certain case it's not what we need.

I fixed the issue for the language switcher with

        if(!function_exists('avia_change_wpml_home_link'))
   {
     add_filter('WPML_filter_link','avia_change_wpml_home_link', 10, 2);
     function avia_change_wpml_home_link($url, $lang)
     {
         global $sitepress;
         if(is_home() || is_front_page()) $url = $sitepress->language_url($lang['language_code']);
         return $url;
     }
   }

but the head_langs function does not have a similar filter and the $lang['url'] still contains the wrong url to the translated entry instead of the blog main url.

@andrea Sciamanna - I know, that's why I provided some code to overwrite the function. However the user is not happy with it and claims our theme is not "compatible with wpml". A complete function overwrite is not a solution for us. Please add a filter or make sure that the $languages array just contains the main blog urls if the function is called on the front page. Or maybe there's an useful filter in the get_ls_languages function code which allows me to replace the url?

November 18, 2013 at 9:48 pm #294344

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi Peter,

Thanks for the explanation. Our developers are already aware of this.

Thanks again. It is truly appreciated.

Thank you.

November 20, 2013 at 12:37 pm #295351

PeterS1

Great - thank you. Did you ask the developer how he wants to solve the issue? I mean do you want to add a front page check in the wpml core code or do you plan to add a filter for us? Both ways would be ok for me but we need to add some code to our theme files if you want to add a filter for the url.

Thanks,
Peter

November 21, 2013 at 5:42 pm #296156

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi Peter,

I have forwarded the details to our Themes & Plugins Compatibility Team and they will contact the author.

We are closing the ticket but we will keep it in our records. Once the plugin is compatible with WPML we will notify you.

Thank you.

December 16, 2013 at 9:00 pm #309246

Jan

Hello,

I am dealing with the same problem.
Have you found a solution?

Thank you,
Jan

The topic ‘[Closed] Filter for head_langs() function’ is closed to new replies.