Skip Navigation

[Resolved] two shortcodes in conditional statement breaks frontend

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

Problem:

Display [wpv-conditional] shortcodes in PHP codes.

Solution:

I suggest you try these:

1) Create a Toolset content template with classic editor, put those shortcode into it

2) In your custom PHP codes, use function render_view_template() to render above content template

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views-api/#render_view_template

This support ticket is created 3 years, 8 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)

Tagged: 

This topic contains 13 replies, has 2 voices.

Last updated by Wim 3 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2072841

Wim
shortcode on frontend.jpg

Tell us what you are trying to do?
I am trying to show two shortcode fields but both wrappen in a conditional statemtent, but they are nested. If i use one condtion for the first shortcode field then the nested condition is being rendered as shortcode on the frontend instead of the actual value.

Example of the code I am using:

[wpv-conditional if="( NOT(empty($(wpcf-title-image))) )"]<div class="vacancy-backimage" style="background-image:url([types field='title-image' output='raw'][/types] );">
<div class="title-overlay">
[types field='titel-over-vacature-afbeelding'][/types]
</div>
</div>
[/wpv-conditional]

I will attach an image how this code renders on the frontend

I need both "title-image" as well as "titel-over-vacature-afbeelding" to be in a condition that if they are empty they should not be shown on the forntend. But whatever I do, I cannot get it to work. I have setup a boolean with AND as an option but that did not work.
I have wrapped them both in conditional statements but that did not work either. So I do hope you can assist me with this?

#2073057
con1.JPG

Hello,

I have tried the same codes you mentioned above in my localhost with a fresh WP installation + the latest version of Toolset plugins, it works fine, see my screenshot.

If you are using WordPress blocks editor, please make sure you have put those shortcodes into a shortcode block:
https://wordpress.org/support/article/shortcode-block/

#2073151

Wim

Hi Thanks,

the code does work if they have values but the code breaks if the image field is left empty. Then the title field renders the short code in the frontend. Have you tried that?
I am using the legacy version of toolset on this site, unfortunately not the blocks.

#2073173

I have tried it again, it works fine:
- With or without empty image field
- Content template with classic editor.

All cases are work without any problem, please check these in your website:

1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

#2073177

Wim
shortcode.jpg

Hi,

Thanks, quess its due to elementor then? I am using elementor in combination with generatepress theme.
But I cannot get it to work, toolset is on the latest version.

See image how it renders.

#2073189

Have you tried the elementor shortcode widget?
hidden link

#2073191

Wim
shortcode.jpg

Hi,

Image field contains image and text field also but this is how its rendered unfortunately. Might it be due to elementor? Toolset is on the latest version and i also use generatepress as a theme

#2073201

You did not answer my questions:
https://toolset.com/forums/topic/two-shortcodes-in-conditional-statement-breaks-frontend/#post-2073173
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

https://toolset.com/forums/topic/two-shortcodes-in-conditional-statement-breaks-frontend/#post-2073189
Have you tried the elementor shortcode widget?

If you need more assistance for it, please provide detail steps to reproduce the same problem, if it needs other plugins/theme, please provide downloadable URLs for them, thanks

#2073203

Wim
after_header.jpg

Hi,

No not the elementor shortcode widget. I am using the element hook of generatepress to insert the shortcode after the header:

#2073213

I suggest you try these:
1) Create a Toolset content template with classic editor, put those shortcode into it
2) In your custom PHP codes, use function render_view_template() to render above content template:
https://toolset.com/documentation/programmer-reference/views-api/#render_view_template

#2073225

Wim

Might be due to generatepress's hook element, and the execution of the shortcode in there when there is a conditional statement. Going to test further

#2073227

Wim

I will try this!

#2073239

Wim

Hi Luo,

Thanks alot this https://toolset.com/forums/topic/two-shortcodes-in-conditional-statement-breaks-frontend/#post-2073213 worked perfect!

Very happy with your support in this!

#2073241

Wim

My issue is resolved now. Thank you!

Thanks alot for your great support and your patience 🙂