translate categories in submenu
-
Hello,
I started using sublanguage to edit an english version on my site. As recommanded, I first placed two links, french and english, in the menu. It is working, but instead of that, I wonder if it could be a switch, showing only one language at a time and switching directly to the other language active page? Right now, it is returning to the homepage.
Also, would it be possible to translate categories. I’m using some in the sub-menu and I’d like them to be translated as well. Thank you for explaining me how to achieve it!
Felix
The page I need help with: [log in to see the link]
-
I wonder if it could be a switch, showing only one language at a time and switching directly to the other language active page
No sorry it isn’t possible in the current version. You need to create a custom switch to achieve this (please refer to FAQ for more info). But I like the idea and I’ll try to bring an option for this in future versions.
would it be possible to translate categories.
Just go to sublangage settings and make sure the “Categories” checkbox is checked under “Translate Taxonomies”.
Thanks for your help
I saw the faq about how to create a custom switch, but I don’t understand where to apply that coding… Is it too complcated to explain briefly?
Hoping to see such an improvement in the near future 🙂
Have a good day!
On second thought I think it’s even better to short-cut the language filter for menu. This snippet should do it. Just put it in you theme “functions.php” file of your theme (preferably the child theme or it will break on your next theme update).
add_filter('wp_setup_nav_menu_item', function($menu_item) { global $sublanguage; if (isset($sublanguage) && $menu_item->type == 'custom' && $menu_item->title == 'language') { foreach ($sublanguage->get_languages() as $language) { if (!$sublanguage->is_current($language)) { $menu_item->title = apply_filters('sublanguage_language_name', $language->post_title, $language); $menu_item->url = $sublanguage->get_translation_link($language); $menu_item->classes[] = $sublanguage->is_current($language) ? 'active_language' : 'inactive_language'; $menu_item->classes[] = 'sublanguage'; $menu_item->classes[] = $language->post_name; } } } return $menu_item; }, 9);
Then go in Display > Menu and remove one of the language links. Of course this will only work if you have exactly 2 languages.
- This reply was modified 5 years, 3 months ago by maximeschoeni.
Hi,
Thank you for this snippet, it’s appreciated!
Unfortunately, it didn’t work, so I replaced everything like before, with two languages links.
When adding this to the fonctions.php file, the code was appearing on top of my site page as well as on top of the WP dashboard. Also, the remainig language link wasn’t changing to the other one when clicking on it.Let me know if you have an idea of what went wrong…
Thanks again!
Felix
Sounds like you pasted the code before the
<?php
tag, you need to paste it somewhere after!This is the only I got in the fonctions.pfp file:
<?php
require_once (get_template_directory() . ‘/framework/load.php’);
?>Then, I pasted here the coding you provided.
Ok so just remove the
?>
tag.Ok, well the same is happening on the dashboard and the website page is not showing at all now.
I’ll keep the changes for a little while if you want to visit felixmichaud.com
I can’t figure the php just by visiting the site… Your functions.php should contain:
<?php require_once (get_template_directory() . ‘/framework/load.php’); add_filter('wp_setup_nav_menu_item', function($menu_item) { global $sublanguage; if (isset($sublanguage) && $menu_item->type == 'custom' && $menu_item->title == 'language') { foreach ($sublanguage->get_languages() as $language) { if (!$sublanguage->is_current($language)) { $menu_item->title = apply_filters('sublanguage_language_name', $language->post_title, $language); $menu_item->url = $sublanguage->get_translation_link($language); $menu_item->classes[] = $sublanguage->is_current($language) ? 'active_language' : 'inactive_language'; $menu_item->classes[] = 'sublanguage'; $menu_item->classes[] = $language->post_name; } } } return $menu_item; }, 9);
I’m sorry, this time the dashboard as well is blank. I’m not able to change back anything right now… I’ll need to fix this before.
Hello,
I’ll wait for you to create a switch option in a further sublanguage version.
Thanks
Until Sublanguage itself has been updated, perhaps this does what you need:
https://wordpress.org/plugins/sublanguage-switcher-widget/
(haven’t tested it)
Or use a bit of CSS to hide the language with thecurrent
class (again, not tested).
- The topic ‘translate categories in submenu’ is closed to new replies.