title: Wordpress PHP dynamic menu item using shortcode
body: <p>This is my menu item structure:</p>
  
  <p><a href="https://i.stack.imgur.com/ErHAe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ErHAe.png" alt="enter image description here"></a></p>
  
  <p>Here's the code im using to create shortcodes to add dynamic menu items:</p>
  
  <pre><code>function my_dynamic_menu_items($menu_items)
  {
  foreach ($menu_items as $menu_item) {
      if ('#short_code#' === $menu_item-&gt;url) {
  
      }
  }
  return $menu_items;
  }
  add_filter('wp_nav_menu_objects', 'my_dynamic_menu_items');
  
  
  function my_custom_menu_item($items, $args)
  {
  preg_match_all('#&lt;li[^"]*"menu-item-([^"]*)" class="shortcode ([^"]*)"&gt;&lt;a[^"]*"[^"]*" href="([^"]*)"&gt;[^&lt;]*&lt;/a&gt;&lt;/li&gt;#', $items, $x);
  if (count($x[0])) {
      foreach ($x[0] as $key =&gt; $value) {
          $items = str_replace($value,'&lt;li id="menu-item-'.$x[1][$key].'" class="shortcode '.$x[2][$key].'"&gt;'.do_shortcode("[".str_replace("#","",$x[3][$key])."]").'&lt;/li&gt;',$items);
      }
  }
   return $items;
  }
  add_filter('wp_nav_menu_items', 'my_custom_menu_item', 10, 2);
  
  
  function show_places_func($atts)
  {
  global $my_category_slug;
  return "&lt;span&gt;&lt;a href='/".$my_category_slug."/local/impacts'&gt;PLACES&lt;/a&gt;&lt;/span&gt;";
  }
  add_shortcode( 'show_places', 'show_places_func' );
  </code></pre>
  
  <p>The issue is that only works for single menu items(no child/subitems). How can I make parent and child items dynamic? Thanks in advance!</p>