Getting menu items in a wordpress site with javascript

I’m trying to see if I can query the wordpress API to get all of the items in the menu of the site using Javascript.

I can see that there is a post here on how to do this in php but I don’t know how to translate this to javascript as it seems to be using the internal wordpress PHP API.

Read More

There is a great library here and I can see that with the following code I can query the site:

var site = Site('<id>', WPCOM);
site.get(function(err, info){
  // `info` data object
});

But I don’t know how to query the menu items or if this is at all possible?

Any help would be appreciated.

Related posts

1 comment

  1. I don’t have the rep to put this link in a comment. I have not used it and don’t know if it will do what you need but how about this page: https://wordpress.org/plugins/wp-api-menus/

    Since I am posting as an answer, here is some info from that page:

    This plugin extends the WordPress JSON REST API with new routes for WordPress registered menus.
    
    The new routes available will be:
    
           /menus list of every registered menu.
           /menus/<id> data for a specific menu.
           /menu-locations list of all registered theme locations.
           /menu-locations/<location> data for menu in specified menu in theme location.
    

    I also found this similar post on wordpress.stackexchange: https://wordpress.stackexchange.com/questions/209381/get-wp-navigation-menu-from-rest-api-v2. It ends up pointing to the same ‘wp-api-menus/’ link.

Comments are closed.