Get multiple shortcode attribute values

Don’t try to shove everything into a single attribute, or a single shortcode even. The string parsing you have to do will get more and more complicated. Try this:

function myshortcode_cb( $atts ) {
  $atts = shortcode_atts( 
    array(
      'cat' => '',
      'title' => ''
    ), 
    $atts
  );
  //   var_dump($atts); // debug
  return "{$atts['cat']} :: {$atts['title']}";
}
add_shortcode('myshortcode','myshortcode_cb');

With this:

[myshortcode cat="key1" title="Title 1" /]

And create a shortcode for each case.

Leave a Comment