Skip to content

Instantly share code, notes, and snippets.

@deshabhishek007
Created June 28, 2018 15:48
Show Gist options
  • Save deshabhishek007/f35255764893fdde844f6d3b5ab00262 to your computer and use it in GitHub Desktop.
Save deshabhishek007/f35255764893fdde844f6d3b5ab00262 to your computer and use it in GitHub Desktop.
Use Following Code with WordPress Plugin - https://github.com/deshabhishek007/wp-menu-extractor
<?php
header('Access-Control-Allow-Origin: *');
$json_path = "http://YourDOMainname.HERE/wp-json/wp-menu-extractor/v2/menus/MENUID";
$json_menu = json_decode(file_get_contents($json_path));
$menu_items = $json_menu->items;
echo '<ul class="menu_ul">';
menu($menu_items);
echo '</ul>';
function menu($child){
foreach($child as $item){
echo '<li> <a href="'.$item->url.'" class="'.$item->classes.'target="'.$item->target.'">'.$item->title.'</a>';
if(isset($item->children)){
echo '<ul class="child_menu">';
menu($item->children);
echo '</ul>';
}
echo '</li>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment