WordPress shortcodes pass array of values

I am creating some WordPress short codes aimed at providing internal navigation on a page (one page with a lot of content sections and it own menu).

This is what I have:

function internal_menu($atts) {
   'href1' => '#jl1',
   'href2' => '#jl2',
   'href3' => '#jl3',
   'href4' => '#jl4',
  ), $atts));
  return '<div id="internalPageMenu">
        <li><a href="' . $href1 . '"><i class="fa fa-bars"></i>link 1</a></li>
        <li><a href="' . $href2 . '">link 2</a></li>
        <li><a href="' . $href3 . '">link 3</a></li>
        <li><a href="' . $href4 . '">link 4</a></li>
add_shortcode('internal-menu', 'internal_menu');

//menu target
function internal_menu_target($atts) {
   'id' => 'jl1',
   'text' => '',
   ), $atts));
   return '<h3 id="' . $id . '">' . $text . '</h3>';
add_shortcode('internal-menu-target', 'internal_menu_target');

And using this in my WordPress admin panel:

[internal-menu-target id="jl1"]
Some content
[internal-menu-target id="jl2"]

My question is, I want to have the menu be dynamic (not restricted to the number of items it can have). for example the short code would be

[internal-menu targets="jl1, jl2, jl3, jl4, jl5, ...etc..."]

I wan this so I can add as many sections/content blocks to the page as I want.

I am relatively new to WordPress, I would appreciate any help?

Source: shortcode

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.