Qtranslate. Logo and Home link of the menu, point to the default language. How to solve it
En esta ocasión, os damos un pequeño pero útil truco para hacer que vuestro logo y enlace del item de menú “home” de la web apunte a la página principal en su correspondiente idioma gracias a Qtranslate.
Cuando insertas Qtransalte en tu web para tener multiidioma, te encuentras que no enlazan correctamente el ítem de menú “Start” y logo. Éstos deberian apuntar a la URL de la página principal de cada idioma pero cuando haces clic siempre vuelve a la página principal del idioma por defecto. Para solucionar este pequeño problemilla os detallamos los puntos a sustituir.
Primero, teneis que editar el fichero de header.php of your template and replace the code that generates the link with the following code where the logo is inserted.
Here we show you an example where the code is located…
....
<div id="header" class="<?php echo $headerstyle; ?>">
<div class="container">
<div class="one-fourth column alpha">
<a id="logo" href="<?php echo site_url(); ?>"><img src="<?php get_option_tree('logo', '', true); ?>" alt="<?php bloginfo('name'); ?>"/></a>
</div><!-- End Header Grid 2 -->
....
You will have to replace the echo site_url(); for this other echo esc_url(home_url());
Save the file
Finally, edit the file qtransalte_hooks.php from the Qtranslate plugin and insert these lines at the end of the code (just before php close ?> )
add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);
function qtrans_in_nav_el($item_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 ) .'"' : '';
// Determine integration with qTranslate Plugin
if (function_exists('qtrans_convertURL')) {
$attributes .= ! empty( $item->url ) ? ' href="' . qtrans_convertURL(esc_attr( $item->url )) .'"' : '';
} else {
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
return $item_output;
}
add_filter('home_url','qtrans_convertURL');
Grabáis el fichero y ahora vereis como vuestro enlace de HOME y LOGO apunta a la página principal de cada idioma.