• Resolved gggt

    (@gggt)


    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/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Matt

    (@sksmatt)

    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/ ( More Videos section )

    Kind Regards!

    Thread Starter gggt

    (@gggt)

    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

    (@sksmatt)

    You can definitely do that, just use the “Insert custom code” behavior, select the PHP language and paste your function there. Remember to return the code instead of echoing directly.

    Kind Regards!

    Thread Starter gggt

    (@gggt)

    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

    (@sksmatt)

    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

    (@gggt)

    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

    (@sksmatt)

    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.