Replace your menu name only in wp_get_nav_menu_items()
function. If menu name and slug does not work (Return false), use Menu ID (visible in Dashboard while editing that Menu).
1 2 3 4 5 6 7 8 9 10 11 | function get_my_menu() { // Replace your menu name, slug or ID carefully return wp_get_nav_menu_items('Main Navigation'); } add_action( 'rest_api_init', function () { register_rest_route( 'wp/v2', 'menu', array( 'methods' => 'GET', 'callback' => 'get_my_menu', ) ); } ); |
Route URL:
1 | https://website.com/wp-json/wp/v2/menu |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.