• timb111

    (@timb111)


    Are nested shortcodes supported? I read your comment from an old thread where you said “In version 5.0+ the shortcode content can have another “shortcoder shortcode” there is no restriction.” but in my case there’s a bug where the 2nd shortcoder closing tag is printed on the web page.

    I’ve created 2 shortcodes. Shortcode 1 is called “sc-test-nest-1” and contains “SC1 content and $$enclosed_content$$”. Shortcode 2 is called “sc-test-nest-2” and contains “SC2 content”.

    In a blank page I’ve inserted this shortcode “[sc name=”sc-test-nest-1″][sc name=”sc-test-nest-2″][/sc][/sc]”.

    The result should be “SC1 content and SC2 content”, but it is producing “SC1 content and SC2 content[/sc]”.

    Can you please advise on whether nested shortcodes should be working, and how I can fix this?

Viewing 1 replies (of 1 total)
  • Plugin Author vaakash

    (@vaakash)

    Hi @timb111,

    When there are nested shortcodes of the same name then WordPress has challenge in parsing which is parent and which is child.

    [sc name="nest-parent1"][sc name="nest-child1"][/sc][sc name="nest-child1"][/sc][/sc]

    In this example, parser does not know [/sc] closes which shortcode. A shortcode can execute even without [/sc]

    The solution should be to use it like below. This would work only for one level nesting.

    [sc name="nest-parent1"][sc name="nest-child1"][sc name="nest-child1"][/sc]

    Since the open and close tags are same there is restriction. If you are using shortcode other than [sc] then everything will work as expected.

    Thanks,

    Aakash

Viewing 1 replies (of 1 total)
  • The topic ‘Nested shortcode not working correctly’ is closed to new replies.