• Resolved lneve

    (@lneve)


    Shortcode Ultimate shortcodes don’t appear to work in a snippet. The opening shortcodes (e.g. [su_column] and [su_row}) are ignored, and the closing tags (e.g. [/su_column] and [/su_row]) are spit out verbatim. Is this expected?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter lneve

    (@lneve)

    I see the problem. With do_shortcode you need to include both the opening and closing tags. That’s why they were acting weirdly.

    So my problem is that I have a lot of content like this that worked just fine before but which I don’t know how to easily convert to use your 2.x plugin:

    [su_row][su_column size=”2/3″]
    [insert_php]
    BLOCK A
    [/insert_php]
    [/su_column][su_column size=”1/3″]
    [insert_php]
    BLOCK B
    [/insert_php]
    [/su_column][/su_row]

    Block A and Block B need to share variables and could easily do so before. But now I have to create separate snippets for them in 2.x and so they can no longer share variables. Is that correct? Is there any way to put both blocks in a single snippet?

    Hello
    I suggest make single snippet and put columns in it.

    $blockA = "something A";
    $blockB = "something B";
    $html = '[su_row][su_column size="2/3"]' . $blockA . '[/su_column]';
    $html .= '[su_column size="1/3"]' . $blockB . '[/su_column][/su_row]';
    echo do_shortcode($html);

    Or you can use global keyword for share variables.

    Also $content variable may be useful. It contains text between tags [wbcr_php_snippet id="xxx"][/wbcr_php_snippet]

    Best regards

    Thread Starter lneve

    (@lneve)

    “something A” and “something B” are two blocks of PHP commands. They can’t just be concatenated and assigned to $html as you do above. What am I missing?

    two blocks of PHP commands

    Please copy your code and paste here

    Best regards

    Thread Starter lneve

    (@lneve)

    Here is my old insert_php code:
    [su_row][su_column size=”2/3″]
    echo “Hello World”;
    [su_column size=”1/3″]
    echo “Goodbye World”;
    [/su_column][/su_row]

    It prints out:

    Hello World Goodbye World

    You say to convert it to a snippet like so:
    $blockA = ‘echo “Hello World”;’;
    $blockB = ‘echo “Goodbye World”;’;
    $html = ‘[su_row][su_column size=”2/3″]’ . $blockA . ‘[/su_column]’;
    $html .= ‘[su_column size=”1/3″]’ . $blockB . ‘[/su_column][/su_row]’;
    echo do_shortcode($html);

    This results in:

    echo “Hello World”; echo “Goodby World”;

    That’s obviously not what I want.

    Thread Starter lneve

    (@lneve)

    Oops, my old insert_php code should have been:

    [su_row][su_column size=”2/3″]
    [insert_php]
    echo “Hello World”;
    [/insert_php]
    [su_column size=”1/3″]
    [insert_php]
    echo “Goodbye World”;
    [/insert_php]
    [/su_column][/su_row]

    Hi

    Option 1
    Put code A and B to individual snippets.
    Create a third snippet with follow code:

    $blockA = '[wbcr_php_snippet id="xxxA"]';
    $blockB = '[wbcr_php_snippet id="xxxB"]';
    $html = '[su_row][su_column size="2/3"]' . do_shortcode($blockA) . '[/su_column]';
    $html .= '[su_column size="1/3"]' . do_shortcode($blockB) . '[/su_column][/su_row]';
    echo do_shortcode($html);

    Option 2
    Rewrite the code of A and B so that it returns the html to a variable.

    Option 3

    ob_start();
    echo "Hello World"; // block A code
    $blockA = ob_get_clean();
    
    ob_start();
    echo "Goodbye World"; // block B code
    $blockB = ob_get_clean();
    
    $html = '[su_row][su_column size="2/3"]' . $blockA . '[/su_column]';
    $html .= '[su_column size="1/3"]' . $blockB . '[/su_column][/su_row]';
    echo do_shortcode($html);

    More about output buffering

    Best regards

    Thread Starter lneve

    (@lneve)

    It’s all a ton of work converting my code. I’ll stick with the old version of this plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Shortcodes Ultimate shortcodes in a snippet?’ is closed to new replies.