Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPML support #50

Open
laustdeleuran opened this issue Nov 20, 2017 · 3 comments
Open

WPML support #50

laustdeleuran opened this issue Nov 20, 2017 · 3 comments

Comments

@laustdeleuran
Copy link

WP-API supports WPML out of the box, so API queries with the parameter lang=CODE or similar just works. This doesn't seem to work in this plugin. Are there any plans to implement this support or am I missing some way it's already implemented?

@isuke01
Copy link

isuke01 commented Mar 1, 2018

Yes that would be nice, now you must find correct navi ID and get this navi by ID

@sarahannnicholson
Copy link
Contributor

Hey @laustdeleuran and @isuke01,
I came across the same thing earlier today! I'm using V2 of this plugin. Here's how I solved it.

  1. In WordPress, localize your English menu WPML translating menus docs
  2. I created a custom plugin in WordPress. WordPress plugins tutorial
  3. In the my plugin file I added this code:
// Add Locale to Menu endpoint		(eg /wp-api-menus/v2/menus/:id )
add_filter('rest_menus_format_menu', 'add_locale_to_menu', 100, 1);
if (!function_exists('add_locale_to_menu')) {
    function add_locale_to_menu($rest_menu) {
		$args = array('element_id' => $rest_menu['ID'], 'element_type' => 'nav_menu' );
		$rest_menu['locale'] = apply_filters( 'wpml_element_language_code', null, $args );
		return $rest_menu;
    }
}

@retzion
Copy link

retzion commented Mar 16, 2021

Would love to use /wp-api-menus/v2/menus?lang=en when you get a chance. Is it in the roadmap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants