WordPress qTranslate Home URL Issue

Background:

Using qTranslate on WordPress is good choice as it is a free plugin that can provide multilingual feature to WordPress, and present various languages neatly.

Issue:

After choosing secondary language, whenever clicking the Home menu, it goes back to default language.

Solution:

Create and activate a child theme (if not done) of the current deploying theme

Create functions.php under the child theme with the following (suggested by Luis Alegandre’s blog):

<?php
// Fix for qTranslate plugin and “Home” menu link reverting back to default language
if (function_exists(‘qtrans_convertURL’)) {
function qtrans_in_nav_el($output, $item, $depth, $args) {
$attributes = !empty($item->attr_title) ? ‘ title=”‘ . esc_attr($item->attr_title) . ‘”‘ : ”;
$attributes .=!empty($item->target) ? ‘ target=”‘ . esc_attr($item->target) . ‘”‘ : ”;
$attributes .=!empty($item->xfn) ? ‘ rel=”‘ . esc_attr($item->xfn) . ‘”‘ : ”;
// Integration with qTranslate Plugin
$attributes .=!empty($item->url) ? ‘ href=”‘ . esc_attr( qtrans_convertURL($item->url) ) . ‘”‘ : ”;
$output = $args->before;
$output .= ‘<a’ . $attributes . ‘>’;
$output .= $args->link_before . apply_filters(‘the_title’, $item->title, $item->ID) . $args->link_after;
$output .= ‘</a>’;
$output .= $args->after;
return $output;
}
add_filter(‘walker_nav_menu_start_el’, ‘qtrans_in_nav_el’, 10, 4);
}
?>
Close Menu