Title: [Plugin: Shortcodes Pro] Pass attributes in shortcode
Last modified: August 20, 2016

---

# [Plugin: Shortcodes Pro] Pass attributes in shortcode

 *  Resolved [gggt](https://wordpress.org/support/users/gggt/)
 * (@gggt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/)
 * Most of the examples concern adding buttons to the MCE editor. Is it also possible
   to pass variables in a shortcode directly?
 * For example:
    [do action=”myshortcode” attributes=”myoption:myvalue”]
 * So with myoption defined as an attribute, Insert Custom Code could do:
    echo “
   The value of my option was”,$atts[‘myoption’];
 * [http://wordpress.org/extend/plugins/shortcodes-pro/](http://wordpress.org/extend/plugins/shortcodes-pro/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Matt](https://wordpress.org/support/users/sksmatt/)
 * (@sksmatt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2375873)
 * Hi Ggggt,
 * I’m not sure If I understood correctly, but If I do, that is what the buttons
   do when attributes are present. Maybe look at the video examples on:
    [http://www.mattvarone.com/featured-content/shortcodes-pro/](http://www.mattvarone.com/featured-content/shortcodes-pro/)(
   More Videos section )
 * Kind Regards!
 *  Thread Starter [gggt](https://wordpress.org/support/users/gggt/)
 * (@gggt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2375885)
 * I would like to use Shortcode Pro to create a generic shortcode returning a subset
   of my custom posts as a list. Along the lines of List Category Posts, but with
   my own selection needs.
 * Unless I am missing something, everything in the (nice) screencasts seems to 
   be about creating interactive shortcodes where either the page author or reader
   can “do” an action on content?
 * I just want to use Shortcode Pro to run a generic function for which I inject
   a parameter as the instance variable each time I use it on a page. No interactive
   capability is required.
 * I’d love this potential to use Shortcode Pro simply to write custom functions
   for page components, which are so transparent to use and manage 🙂
 * Does that help to explain?
 *  Plugin Author [Matt](https://wordpress.org/support/users/sksmatt/)
 * (@sksmatt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2375916)
 * You can definitely do that, just use the “[Insert custom code](http://lab.mattvarone.com/plugins/shortcodes-pro/docs/lessons/Insert_Custom_Code.html)”
   behavior, select the PHP language and paste your function there. Remember to `
   return` the code instead of echoing directly.
 * Kind Regards!
 *  Thread Starter [gggt](https://wordpress.org/support/users/gggt/)
 * (@gggt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2375919)
 * I’m still not clear, sorry. Here is a simplified example of the concept for a
   php function listmovies to say return genre listings from a custom post type 
   for movies.
    — Here are the action movies: [do action=”listmovies” attributes
   =”genre:action”]
 * Here are the romance movies:
    [do action=”listmovies” attributes=”genre:romance”]—
   As you can see, each shortcode call contains it’s own field:specifier pair that
   the script will use to select the required posts to return.
 * The question is, what is the correct syntax in Shortcode Pro for passing that
   parameter pair from the shortcode to the function?
 * Apologies if I have been confusing.
 *  Plugin Author [Matt](https://wordpress.org/support/users/sksmatt/)
 * (@sksmatt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2375936)
 * Simply add a new attribute with the id `attributes`. You will be able then to
   grab it’s value with PHP like this: `$atts['attributes'];` . From there you can
   do whatever you want with that value. The ideal anyways would be to create a 
   shortcode attribute for each of the parameters you need instead of concatenating
   all in one.
 * Kind Regards!
 *  Thread Starter [gggt](https://wordpress.org/support/users/gggt/)
 * (@gggt)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2375949)
 * Shortcode = test1
    Behaviour = Insert custom code Attribute = testa Language 
   = PHP Code = echo $atts[‘testa’]; return;
 * Embed on page = [do action=”test1″ testa=”simple when you know how”]
 * Output = simple when you know how
 *  Plugin Author [Matt](https://wordpress.org/support/users/sksmatt/)
 * (@sksmatt)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2376015)
 * Code line should be:
 * `return $atts['testa'];`
 * Always remember to return the content instead of echoing.
 * Kind Regards!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘[Plugin: Shortcodes Pro] Pass attributes in shortcode’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/shortcodes-pro_434343.svg)
 * [Shortcodes Pro](https://wordpress.org/plugins/shortcodes-pro/)
 * [Support Threads](https://wordpress.org/support/plugin/shortcodes-pro/)
 * [Active Topics](https://wordpress.org/support/plugin/shortcodes-pro/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shortcodes-pro/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shortcodes-pro/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Matt](https://wordpress.org/support/users/sksmatt/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-shortcodes-pro-pass-attributes-in-shortcode/#post-2376015)
 * Status: resolved