WordPress.org

Ready to get started?Download WordPress

Forums

Shortcodes Pro
[resolved] Shortcode Inside of the Shortcode (4 posts)

  1. Jason
    Member
    Posted 2 years ago #

    Love this plugin! I have a problem with adding shortcode inside of shortcode.

    For example, I'm using a shortcode like this:

    [do action="myaction"]

    My Content

    [gravityform id="1" name="My Gravity Form Shortcode" title="false" description="false" ajax="true"]

    [/do]

    The Shortcode [do action…] works however the Gravity Form shortcode in the middle does not and is shown as text. Any ideas on how I can get the shortcode inside the [do action…] shortcode to work?

    I found something at this site: http://stackoverflow.com/questions/4773186/shortcodes-inside-a-shortcode-wordpress

    But I don't' quite understand it or how I could apply it and implement it into this scenario. Any help would be great.

    http://wordpress.org/extend/plugins/shortcodes-pro/

  2. Matt
    Member
    Plugin Author

    Posted 2 years ago #

    Hi iJas0n,

    I would suggest creating only one shortcode and process the Gravity Form inside. You can return the results of do_shortcode();.

    Kind Regards!

  3. GabLeRoux
    Member
    Posted 2 years ago #

    I use this plugin alot for interface and this is also something I'd like to do natively. After trying some tricks, I found a way to accomplish this.

    This code doesn't work:

    [do action="nine_six_zero_gs" grid="6" appearence="none"]<p><strong>Lorem Ipsum</strong> is simply dummy text of the printing.</p>
    [do action="button" color="black" url="http://www.google.ca/" target="_blank" size="medium" align="right"]Hire us![/do][/do]

    Because it stats doing the shortcode "do" inside the other one but breaks at the fist "[/do]" leaving the last [/do] written as text in the content (sadface).

    But this one does!:

    [do action="nine_six_zero_gs" grid="6" appearence="none"]<p><strong>Lorem Ipsum</strong> is simply dummy text of the printing.</p>
    [do action="button" color="black" url="http://www.google.ca/" target="_blank" size="medium" align="right" content="Hire us!"/][/do]

    1st, I added do_shortcode to the content of action="nine_six_zero_gs"
    See the code below:

    return '<div class="grid_' . $atts["grid"] . ' ' . $atts["appearence"] . '">' . do_shortcode($content) . '</div>';

    And here's the little tweak: my php code for the action="button" starts with this:

    if ($content == '')
    $content = $atts["content"];

    So everything works fine!

    In your case iJas0n, to be more clear, yout code:

    [do action="myaction"]

    My Content

    [gravityform id="1" name="My Gravity Form Shortcode" title="false" description="false" ajax="true"][/gravityform]

    [/do]

    could work fine just by adding do_shortcode($content) to the php code of your "myaction" shortcode:

    return 'some html or php before ' . do_shortcode($content) . ' some html or php after';

    I Hope it helps someone out there.

    Ps.
    Note to the dev: There should be an option allowing recursivity of do_shortcode() so it would be a bit easier than tweeking all of the shortcode made in this plugin :).

    By the way, this plugin is awesome :D.

  4. Jason
    Member
    Posted 1 year ago #

    Awesome! Thanks GabLeRoux! That worked like a charm.

    For those others out there just to clarify:

    1) Create shortcode with whatever code you want. Add code to your page:

    [do action="myshortcode"] My Content [/do]

    2) Then to add other shortcode inside this shortcode, return to create shortcode, but use this instead:

    return ' ' . do_shortcode('[other shortcode here]') . ' ';

    3) Then add the new shortcode in inside the other shortcode, making sure it only have one closing [/do]. So it would now look like this:

    [do action="myshortcode"] My Content [do action="my2ndshortcode"/] [/do]

    Thanks again for your help!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic