Nested shortcodes, shortcodes in attributes

Table of contents

  1. Introduction
  2. Nested shortcodes with the same tag names
  3. Use of shortcodes inside the attributes of other shortcodes

Introduction

This article is rather a bad example and was published here just because many users wonder how to create nested shortcodes. I do not recommend to use approaches described in this article, unless it is really necessary. Besides, I would like to mention that the same behaviour is not guaranteed in all shortcodes.

Some SU shortcodes can be nested, like this:

[shortcode]
  Hello, [another_shortcode]
[/shortcode]

Nested shortcodes with the same tag names

Shortcodes with the same names cannot be nested into each other. For example, the structure presented below will not work:

[su_box]
   [su_box] This will NOT work [/su_box]
[/su_box]

If you want to nest shortcodes with the same names anyway, then you should use underscore character “_” before the name of a nested shortcode, e.g.:

[su_spoiler]
  [_su_spoiler] Content [_/su_spoiler]
  [_su_spoiler] Content [_/su_spoiler]
[/su_spoiler]

In case if you need to nest shortcodes with the same name more than one level deep, you can enable the deprecated nesting mode. This implementation was used in the plugin earlier, but now it is disabled by default due to complexity. Navigate to Dashboard – Shortcodes – Settings – Advanced Settings, tick the Nested shortcodes alternative mode checkbox, save changes and use the following syntax:

[su_spoiler]
[_su_spoiler]
[__su_spoiler]
[___su_spoiler]
Hidden content
[___/su_spoiler]
[__/su_spoiler]
[_/su_spoiler]
[/su_spoiler]

Use of shortcodes inside the attributes of other shortcodes

Some plugin shortcodes allow using other shortcodes in their attributes.

To do that, in nested shortcodes replace square brackets ([, ]) with curly brackets ({, }) and double quotes (") with single quotes ('). Example:

[su_spoiler title="{user field='display_name'}"] Content [/su_spoiler]
Helpful?
🤝 Thank you!