Skip Navigation

[Resolved] Shortcodes for CPF in Conditional not working Divi Theme Builder

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

Problem:

The customer was attempting to use a shortcode to display a custom field (CPF) conditionally within the Divi Theme Builder’s tab module. While the shortcode functioned correctly outside the Theme Builder, it only displayed the raw shortcode within the builder, failing to render the expected content. The issue appeared to stem from Divi’s Theme Builder potentially overwriting post variables required by shortcodes.

Solution:

A workaround was suggested due to the limitations in Divi’s handling of shortcodes within the Theme Builder. A custom PHP function was created and added to the theme's functions.php file to handle the conditional logic and output the custom field directly:

function display_reisekosten_func() {
    if (get_post_meta(get_the_ID(), 'wpcf-reisekosten-pauschal-individuell', true) == '1') {
        return '<h2>Reisekosten</h2>' . do_shortcode('[types field="reisekosten-min-km"][/types]');
    }
}
add_shortcode('display_reisekosten', 'display_reisekosten_func');

The shortcode [display_reisekosten] could then be used within a Divi Code Module to render the content conditionally. While not a guaranteed solution, this approach provided a viable alternative until Divi resolves the underlying issue.

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 4 replies, has 3 voices.

Last updated by Mateus Getulio 3 weeks ago.

Assisted by: Mateus Getulio.

Author
Posts
#2779822

Tell us what you are trying to do?
I am using Divi Theme Builder Template for a site and try to use a shortcode to display a cpf inside of a conditional. The Shortcode is inside of a tab-module.
Here is an example code:
The condition is working fine. Problem is that the shortcode is not showing the content, it just shows the shortcode.

If I use the shortcode on a site in a tab-module (and not on the divi builder) everything is working! The shortcode does what I expected.

[/wpv-conditional][wpv-conditional if="( $(wpcf-reisekosten-pauschal-individuell) eq '1' )"]
<h2>Reisekosten</h2>
[types field='reisekosten-min-km'][/types]

Is there any documentation that you are following?
https://toolset.com/forums/topic/conditional-shortcodes-within-a-divi-builder-template/
https://toolset.com/forums/topic/shortcodes-inside-conditional-doesnt-work/
https://toolset.com/forums/topic/conditional-display-of-custom-field-not-working-in-divi-global-module/

Is is possible to get it working in a Tab-Module in the Divi Theme-Builder? Or another workaround?

#2779869

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share details on what Divi template you added conditional statement and what conditional statement is working and where exactly on what part of the Divi template you would like to see it working.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2780013

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there,

Minesh is off today, so I'll be taking this ticket over in his absence.

I would suggest getting in touch with the Divi team for this, because the types shortcode works outside of the Theme-Builder Template.

I know in the past the Divi theme builder was breaking some shortcodes because Divi was overwriting the post variable that many shortcodes require.

It could be that Divi broke the shortcodes here again.

However as far as I can see our types shortcode is still working fine when added outside Divi.

Thanks,
Mateus

#2780105

Thank you for replying. I contacted the Divi support, they were able to replicate the issue. They told me, that they need complex adjustments within the Theme Builder to fix it.

Unfortunately the are not able to give me a solution how to handle this problem. Maybe you as a toolset expert know a solution or another workaround to get it working?
If not, no worries.
Thanks beforehand.

#2780224

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi Sebastian,

Thanks for following up. Given the limitation within Divi's Theme Builder, there’s one workaround you could try, though I can’t guarantee it will fully resolve the issue given the challenges Divi has with shortcode processing. Here’s an approach that may provide a workaround:

You could add a custom function to your theme’s functions.php file, which handles the conditional logic and outputs the custom field. Here’s an example:

function display_reisekosten_func() {
    if (get_post_meta(get_the_ID(), 'wpcf-reisekosten-pauschal-individuell', true) == '1') {
        return '<h2>Reisekosten</h2>' . do_shortcode('[types field="reisekosten-min-km"][/types]');
    }
}
add_shortcode('display_reisekosten', 'display_reisekosten_func');

After adding this to your theme, you can use [display_reisekosten] in a Divi Code Module within your template to attempt to display the conditional content.

Important Disclaimer

Since the issue stems from Divi’s handling of shortcodes in the Theme Builder, there’s a chance this workaround may not work consistently. If it doesn’t work, I’m afraid a more robust solution would depend on Divi making adjustments on their end.

Let me know how it goes!

Best regards,
Mateus

#2780389

Hi Mateus,

thank you for your help. I wish the divi support would also be so solution-oriented.
My code is a bit more complex than this example code but it's working.
I think it's the best solution . Hopefully the divi team is going to fix their bug.