Use Shortcodes within Divi Module fields
The plugin detects and runs shortcodes in various Divi Builder module fields, including:
- Accordion Module
- Title
- Bar Counter Module
- Percent
- Blurb Module
- Title
- Image
- URL
- Alt
- Button Module
- Button Text
- Button URL
- Call To Action (CTA) Module
- Title
- Button Text
- Button URL
- Circle Counter Module
- Title
- Number
- Columns
- Column Link URL
- Contact Form Module
- Redirect URL
- Success Message
- Message Pattern
- Field Titles (Placeholder)
- Fullwidth Header Module
- Title
- Subheading Text
- Button #1 Link Text
- Button #2 Link Text
- Button #1 Link URL
- Button #2 Link URL
- Fullwidth Image Module
- Image URL
- Title Text
- Alt
- Image Module
- Image URL
- Link URL
- Title Text
- Alt
- Number Counter Module
- Title
- Number
- Pricing Table Module
- Title
- Subtitle
- Currency
- Sum
- Frequency
- Button Text
- Button URL
- Rows
- Row Link URL
- Slider Module Slides
- Title
- Button Text
- Button URL
- Title Text
- Alt
- Social Media Follow Module
- Account Link URL
- Tab Module
- Title
- Toggle Module
- Title
- All Modules, Rows and Sections
- Background Image URL
- Module Link URL
- CSS ID
- CSS Class
- Third-Party Plugins
- Divi Areas Pro - Section Popup ID
- Divi Supreme Pro - Card Carousel Module Image
Built-In Shortcodes
The plugin includes the following shortcodes for use in the module fields:
- [site_url] – Adds the site URL (no trailing slash). Useful for ensuring that your URLs always point to the correct site, even if you change domains / move your site.
- [dbsce_post_id] – Returns the current post id.
- [dbsce_echo_test] – Returns the text "test". Useful for checking if shortcodes are being processed.
- [custom_field name="xxx" post_id="yyy"] – Returns the value of the custom field named "xxx" set in the page / post with id "yyy" (defaults to current page / post if post_id attribute omitted).
Hey, will this plugin help me to add any shortcodes into a module or row URL. Even third parties sorts as LearnDash and Woocommerce?
Hey Kenneth, yes absolutely. The only requirement is that your third party shortcodes return just the URL, i.e. they don't return a full HTML link. Even if they return a full HTML link, this isn't usually a problem as it's possible to create a little wrapper shortcode that extracts the URL from the shortcode's output and that's something I can help you with if needed. I hope that helps, but let me know if you have any further questions about it. Thanks!
Hey Dan, thanks for the reply. Just a clarification, might have been answered previously, then I apologize for misunderstanding.
Some of the shortcodes, for example from LearnDash, are variable URLs, they referring to which course the student last viewed and completed (so they never stay the same). Will that still be able to extract the URL if needed? Since it’s not just one single URL.
Hey Kenneth, yes, it's totally possible to extract the URL even if it varies. All we need to do is extract the part of the output that contains the URL and return whatever that is. For example, if the shortcode returns a HTML link, then we can just locate the contents of the link's "href" attribute (which contains the URL) and return its value, giving us the URL we need. If you like, let me know the names of the shortcodes your looking at and I'll confirm how it can be done.
Hey Dan, Thanks for the reply. As for now it’s mostly two shortcodes that I need to work. Both will be used as URL link in a blurb and a row.
One from LearnDash – [uo_learndash_resume_link], and then one from Uncanny Toolkit for LearnDash – #uo_log_out_link.
You're welcome, Kenneth, and thanks for the details.
For the resume link, if you use [uo_learndash_resume_link url_only="yes"], it should return just the URL.
For the logout shortcode, you can create a URL-only version with this PHP wrapper shortcode:
function db_uo_logout_url( $atts ) {
$output = do_shortcode( '[uo_logout]' ); // Replace with your shortcode
if ( preg_match( '/href=["]([^"]+)["]/', $output, $matches ) ) {
return esc_url( $matches[1] );
}
return '';
}
add_shortcode( 'db_uo_logout', 'db_uo_logout_url' );
You can then use [db_uo_logout] to get the URL alone. This code can be added to your child theme's functions.php file or by using a plugin like Code Snippets.
You should then be able to use these in the blurb / row URL link field when Divi Shortcode Enabler is installed.
I hope that helps, but feel free to ask if you need further assistance. Cheers!
Question – Will this plugin allow short-codes to continue to work and be loaded after the new Divi 5 theme is released (which I vaguely understand seeks to move away from short-codes)?
Thank you.
Hi BPM, yes it will. Divi Shortcode Enabler will continue to allow shortcodes to be loaded and work in Divi 5. Divi 5 is only moving away from its own internal use of shortcodes for storing layouts, which won’t affect the use of other shortcodes within module fields. Therefore, the plugin will remain just as relevant in Divi 5 as it is now. I'm actively working on adding Divi 5 support to all my plugins, including Divi Shortcode Enabler. I hope that helps!
Hi Dan.
I was hoping to use this to dynamically (using a shortcode) populate the "Email Address" (recipient field). Is that possible?
Hey Boris, you mean in the contact form, right? Yes, absolutely. You can use shortcodes in the contact form's "Email Address" field to dynamically set the recipient email. I hope that helps!
Hi,
there is a bug in the new version. In the file DBDSE_EnableShortcodesInBackgroundImageUrl.php
to may fields are taken into consideration it seems when parsing shortcodes in background images.
The result is that I get background images in strange places and some that overwrites mobile settings (fx background image on desktop and tablet but not on mobile -> background image is shown on mobile regardless).
Hi Johannes, I've identified the problem and have prepared a fix that will be included in the next plugin update, version 1.4.7. This update refines the mechanism that applies background URL CSS, ensuring it is only in effect when there is actually a shortcode used in the background. I think that should clear up the issues you've been having. I'm hoping to release the update early next week and will let you know as soon as it's available. It should hopefully clear up the issues you've been seeing, but if you do encounter any further problems, please don't hesitate to let me know. Thanks!
Can i you my own shortcodes?
Hi Jonas. Yes, you can use your own shortcodes with Divi Shortcode Enabler. To do so, you need to first add your shortcode to WordPress, e.g. by entering its PHP code into the functions.php of your child theme (if you're using one) or using a plugin such as Code Snippets. Then you can just enter your shortcode into the button module field you want to use it in.
The main requirement for this to work is that your shortcode returns a valid value (and nothing else) for the field it is being used in. So if you want to use it, say, in the Button Link URL field, it should return a valid URL only – it shouldn't, for example, return any HTML tags with that. Note that if you want to display some HTML content in a popup when the button is clicked, then Divi Shortcode Popup Module may be the better plugin for you.
If you'd like some help with the, please feel free to send through some details of the shortcode (e.g. its PHP code) and any errors you're getting when you use it. Thanks!