• Resolved jfantasybooks

    (@jfantasybooks)


    Hello!

    Details:

    Name: JFantasyBooks
    WordPress Version: 4.6.1

    Problem:

    I have an issue with activating a shortcode within the ‘<‘, ‘>’ tags in wordpress.

    Shortcodes themselves work, for example: <div [shortcode]> is fine.

    Problem comes when the shortcode I have has a looped output, and to activate it, I need something like:

    [shortcode-activate]

    [shortcode 0]

    [/shortcode-activate]. or else by itself, the shortcode results shows nothing.

    In a normal circumstance, it works, but when I do this:

    <tbody>
    [shortcode-activate]
    <tr value=[shortcode 0]>
    <td class=somevalue></td>
    <td>[shortcode 1]</td>
    <td>[shortcode 2]</td>
    </tr>
    [/shortcode-activate]
    </tbody>

    Only shortcodes 1 and 2 are activated. shortcode 0 just shows up blank.

    **Thing is, I used the views plugin before, and when I used their shortcodes, which looped using a class <wpv-loop></wpv-loop>, it worked. The only difference between me and them is I have a shortcode to loop it. So, I know it can work.

    And it’s not just this:

    If I put the shorcode within this: [shortcode-activate][shorcode 1][/shortcode-activate]

    only shortcode 1 initiates. Shortcode 0 comes up blank.

    Any thoughts?

    I would appreciate it a lot.

Viewing 8 replies - 1 through 8 (of 8 total)
  • “The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do_shortcode()” – https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes

    I suspect that the Shortcode author of one of the shortcodes that you are having trouble with is not doing this (“recursively calling do_shortcode()”).

    Re-reading your question, I realize now that you may actually be writing your own shortcodes.

    If so, what I’m talking about is a shortcode that requires an [/shortcode] end tag and returns $content as a parameter. First thing to do with $content is $content = do_shortcodes( $content );

    Thread Starter jfantasybooks

    (@jfantasybooks)

    Hmmm. Thanks for the quick reply.

    Can you be a little more specific on how to initialize returning content as a parameter?

    so for:

    function some_function($atts)
    {
    $content = get_post_meta(get_the_ID(), ‘some_code’, true);
    return $content;
    }

    add_shortcode(‘shortcode 0’, ‘some_function’);

    I would do something like this instead?:

    function some_function($atts)
    {
    $content = get_post_meta(get_the_ID(), ‘some_code’, true);
    $content = do_shortcodes( $content );
    return $content;
    }

    add_shortcode(‘shortcode 0’, ‘some_function’);

    ref. – https://codex.wordpress.org/Shortcode_API

    What you have displayed is not incorrect, just unnecessary. It is the function for [shortcode-activate] that needs to handle nested Shortcodes. It would become something like this:

    add_shortcode(‘your_initials_shortcode_activate’, ‘your_initials_shortcode_activate’);
    function your_initials_shortcode_activate( $att, $content ) {
        $content = do_shortcodes( $content );
    • This reply was modified 9 years, 6 months ago by jon.
    Thread Starter jfantasybooks

    (@jfantasybooks)

    Thank You, I will try it.

    Thread Starter jfantasybooks

    (@jfantasybooks)

    So, I had this plugin designed for me, and only now I realized the nested shortcodes are not activated within the <,> tags. The designer won’t help as his ‘job’ is technically done, as it has the requested features.

    I see that I already have the do_shortcodes for content…

    Something like

    function your_initials_shortcode_activate($atts = array(), $content = null)

    .. a few if statements …

    $cf_content_build = ‘ ‘;
    $loop = new WP_Query($args);
    while ($loop->have_posts()):
    $loop->the_post();

    // echo do_shortcode($content);
    $cf_content_build .= do_shortcode($content);
    endwhile;

    wp_reset_query();
    wp_reset_postdata();

    return $cf_content_build;

    Since that’s the case, I am not sure if that’s the problem.

    What do you think?

    Just saw this now.

    What you have done should work. I’m out of ideas. And not sure what else to say.

    Thread Starter jfantasybooks

    (@jfantasybooks)

    I actually figured it out eventually. Thank You for helping, @jonradio

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

The topic ‘Shortcode looping/ html tags’ is closed to new replies.