qtranslate-slug
qtranslate-slug copied to clipboard
Translate support in Custom links in Nav Menus
I think andreu is talking about the custom links where you input the links manually. It is not a bug. I assume you just didn't implement the functionality to that feature. However, like andreu said, by manually applying qTranslate's tags (<--:en-->), it will automatically become compatible with the plugin's nav menu translator.
do you have a solution at the moment?
You can very easily add different languages by using the shortcodes: [:en]Home [:de]Startseite [:tr]Anasayfa
You just add these at the "Navigation Label" of your menu.
thanks, this works great
2013/5/27 Deelux [email protected]
You can very easily add different languages by using the shortcodes: [:en]Home [:de]Startseite [:tr]Anasayfa
— Reply to this email directly or view it on GitHubhttps://github.com/not-only-code/qtranslate-slug/issues/20#issuecomment-18501820 .
http://www.arkvannoach.com/
Using a quick tag works for the name of the link, but I'm actually curious about the URL of the custom link. In my case, my custom link is an inline anchor link. WP doesn't seem tike quick tags or xml language tags. It just removes everything.
Will it be possible to define a different link for each language too, i would really need this. So somthing like "[:de]http://google.de[:en]http://google.com" could work.
After all day of reaseach on custom link I was able to fix it by creating two menus, one in english (Nav_en) and one in spanish (Nav), which is also selected as default menu, and default language is Spanish. Then on Header.php I added this code:
Let me know if it worked for you, Cheers!!
Wow, this worked for me as well.
If you only have 1 or 2 custom links in your navigation, you could just add some inline css to your header with your if statement solution, in order to show/hide the custom links depending on the language.
For example:
Added as enhancement https://github.com/not-only-code/qtranslate-slug/issues/55
So I just encounter a problem with the code... It doesn't work with Chrome installed in languages that are neither english or spanish... Maybe it's missing one generic line of code for a default language, Any thoughts on this?
For example, to use english as the fallback language, use this:
} else {
// the default lang, u can use the english code
}
On Thursday, October 24, 2013, Johanna wrote:
So I just encounter a problem with the code... It doesn't work with Chrome installed in languages that are neither english or spanish... Maybe it's missing one generic line of code for a default language, Any thoughts on this?
— Reply to this email directly or view it on GitHubhttps://github.com/not-only-code/qtranslate-slug/issues/20#issuecomment-27027727 .
So for example
if (qtrans_getLanguage()=='es') {
wp_nav_menu( array('menu' => 'Nav' ));
} else {
wp_nav_menu( array('menu' => 'Nav_en' ));
}
Try and copy/paste this in your function.php:
// Makes menu urls work with Qtranslate
function qtranslate_menu_item( $menu_item ) {
if (stripos($menu_item->url, get_site_url()) !== false){
$menu_item->url = qtrans_convertURL($menu_item->url);
}
return $menu_item;
}
add_filter('wp_setup_nav_menu_item', 'qtranslate_menu_item', 0);
/**************************************************/
This last answer works like a charm but not for themes with a top left icon going to the home page. I use Responsive theme, and there is an icon the upper left corner of the header, above the main menu, which gets the user to the home page. This link resets the current language.
Woops, actually the link is alright. Sorry for the previous post
Thanks bmachuel! It works!
hello,
I tried the "bmachuel" solution, and looks solve the problem of showing the url in the menu.
My problem is when I try to save it. When I put the url with tags: "http://xxxxx/pt
http://xxxxx/en http://xxxxx/es"The string is not commited in the database when i save in Admin page.
I have to updade in database the string, so I can retrieve the url with the bmachuel solution.
Somebody have any idea?
Thank you, bmachuel, works perfectly. I just have one little issue: I have a language selector in one menu (custom links which link to the domain itself (language 1) and the domain/sl (language 2). Your function now translates these links as well, turning them into domain/sl (language 1) and domain/sl/sl (language 2).
Is there away to make your function work only on one of the two menus? Or not allow it to translate in the second?
Thanks for your help,
derbub
Hi Derbub,
Have you tried Qtranslate's built-in language selector?
Benoît
@bmachuel : thanks for your solution but when I put your code at the end of function.php (WP 3.8.1), an error occurs : Fatal error: Call to undefined function add_filter() in /home/MyName/public_html/wp-includes/functions.php on line 4205
@lepatachou no no no , that code should go into your theme's function.php. don't edit that file wp-includes/functions.php, its the wordpress core file. If you update wp, all the changes will be lost.
I don't understand the posted solution of you bmachuel. I want the shortcodes to work with my custom links. By adding your code to functions.php it still doesnt save the shortcoded custom link fields, so it doesn't do anything.
Please explain further for non-coders.
@LC43 : Thanks for your remark. It works fine now. @wouts : shortcodes are not saved in data base but added, by this code, dynamicaly in the link.
Aha, yes it works. I checked the code and it looks for your site url (your domain) in the custom link. It didnt work because i had my links like this: /#link (without the domain in front). made them like this: http://mydomain.com/#link And it works. Thanks for your reply lepatachou, and also big thanks to bmachuel for the code ofcourse!
Hey bmachuel,
the widget is not really an option for me, as I need to include the language selector in the top primary menu. Is there maybe a way to disable your function for a certain menu, keeping it working for the other menus?
@derbub Can you post a link to your webpage so that we have an idea of what you are trying to achieve?
@bmachuel thanks, qtranslate_menu_item is a lifesaver!
hi, i have inserted the @bmachuel code in my theme functions.php, but, a question, how i can insert my custom link in menu? I need to make a menu with links to an external site, but with correct language redirection. qtrans Shortcodes don't works. Can u help please?
it works, but i have checked the code and it looks for your site url, now i have another problem, i need to insert an external custom link (from another site) and NOT from my site.
@bmachuel hi, just great piece of code. Is it possible to somehow exclude 1 or more items from menu? I mean everywhere give me www.xxxxxx.com/pl/xxxxxx,but i need i one item to give me wtihout language- just pure www.xxxxx.com/xxxx. is it somehow with some class or what? Thanks all best
Hello,
@wouts - how did you add the custom urls? Because I have pasted the code from @bmachuel and also tried lots of different ways to put the links in the menu (I am ok with the headers using "За тебFor You" for instance) but with the urls I have no success. And the theme doesn't give me to create different menus (because it has different navigations and for each navigation it only gives me one option to put only one menu there).
Please, I could really use some help here :)