Skip Navigation

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.

Our next available supporter will start replying to tickets in about 2.41 hours from now. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by Karl 2 years, 10 months ago.

Assigned support staff: Yuri.

Author Posts
September 27, 2017 at 7:58 am #1384508

Karl

I have the code below in my functions.php for redirecting back to the homepage when a user clicks the logo.
But when clicked from within a translated language it redirects back to the English Main language instead of the homepage of the translation.

What is the correct way to link to the homepage?

function pp_add_module_before_menu() {
echo '<div class="logo-menu"><a href="/"><img src="logo.png" /></a></div>';
}
add_action('pp_advanced_menu_before', 'pp_add_module_before_menu');

September 27, 2017 at 8:52 pm #1385435

Yuri

Hi, the correct way to fetch the home URL for any language is to use our API. Specifically the "wpml_home_url" filter. You can find the documentation for this hook here: https://wpml.org/wpml-hook/wpml_home_url/

Let me know if this was what you were looking for.

September 27, 2017 at 8:55 pm #1385438

Karl

How can I get this into my function.php file? Do you have some code for me?

September 27, 2017 at 9:18 pm #1385446

Yuri

Hi, to use the code you sent as an example here it is modified:

function pp_add_module_before_menu() {
$my_home_url = apply_filters( 'wpml_home_url', get_option( 'home' ) );
echo '<div class="logo-menu"><a href="'.$my_home_url.'"><img src="logo.png" /></a></div>';
}
add_action('pp_advanced_menu_before', 'pp_add_module_before_menu');

Let me know if everything works out right.

September 28, 2017 at 10:53 am #1386065

Karl

Perfect! Thank you Yuri.