Skip Navigation

[Resolved] Cannot render shortcode within another shortcode from View

This thread is resolved. Here is a description of the problem and solution.

Problem:

The shortcode [design-gallery] can be rendered if I put in the post/page but it can't be rendered if putting it in Content Template, what is the problem?

Solution:

Please try to modify this line of PHP codes, from:
return $content;

To:
return do_shortcode($content);

Relevant Documentation:

https://codex.wordpress.org/Function_Reference/add_shortcode

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by kelvinL-2 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1295385

Dear Sir/Madam,

I have a custom shortcode

[showwhenip ip="14.198.105.233"]
  [design-gallery]
[/showwhenip]

Below is code of shortcode [showwhenip]

function func_showwhenip($atts, $content = null) {
    if ($atts['ip'] == $_SERVER['REMOTE_ADDR']) {
        return $content;
    } else {
        return "<!-- IP address is " . $_SERVER['REMOTE_ADDR'] . "-->";
    }
}
add_shortcode('showwhenip', 'func_showwhenip');

the shortcode [design-gallery] can be rendered if I put in the post/page but it can't be rendered if putting it in Content Template, what is the problem?

I registered the shortcode to Toolset > Settings > Front-end Content > Third-party shortcode arguments or Functions inside conditional evaluations but it seems not related.

#1295397

Hi kelvin

Please try to modify this line of PHP codes, from:
return $content;

To:
return do_shortcode($content);

More help:
https://codex.wordpress.org/Function_Reference/add_shortcode

#1295413

Dear Luo Yang,

How can I do if my content including text and shortcode together? There is no problem from post/page.

Best regards,

Kelvin.

#1295423

The WordPress function do_shortcode() will parse shortcodes insider variable $content, it should when you using content including text and shortcode together too.

#1295541

My issue is resolved now. Thank you!