Filtering the output of Divi Module Fields

Written by Dan Mossop

Divi uses the values entered in a module's settings to generate the HTML output for the module. While Divi provides filters to modify the module setting values before they are used, it doesn't typically provide a way of modifying the values as they are finally used in the HTML. As such, it's not possible to make changes to the way Divi processes these values. For example, if you want to include some HTML in a field (perhaps adding a span tag to allow styling of part of a module title), Divi will encode the HTML so that it is displayed to the user, rather than included as part of the page structure, and offers no easy way to change this behavior. Here's what to do about it.

Filter the Output of Module Fields using Divi Shortcode Enabler

Divi Shortcode Enabler allows you to use shortcodes in a variety of module fields, where it's not normally possible to do so. The shortcode output is placed into the module field prior to Divi generating the HTML of the page. This normally works well and allows for dynamic pages and easy integration with a many plugins. However, if the shortcode being used includes HTML in its output, as many do, this HTML will usually be displayed to the user rather than being included in the page structure as would be expected. 

To address this I've started adding a feature in Divi Shortcode Enabler which enables filtering of the final output of fields. This allows, for example, HTML in a field to be decoded in the final module output so that it becomes part of the module HTML structure, rather than just text displaying HTML tags.

Here are examples of the PHP code needed to decode HTML in various fields.

I've only added this filtering to a limited number of fields at the moment – if you need it on another field, let me know in the comments. Note that with Divi Shortcode Enabler installed, you can use these output filters, even if you aren't using shortcodes in your fields.

Accordion Module

add_filter('dbsce_accordion_item_title', 'html_entity_decode');

Button Module

add_filter('dbsce_button_button_text', 'html_entity_decode');

Contact Form Module

add_filter('dbsce_contact_form_success_message', 'html_entity_decode');

CTA Module

add_filter('dbsce_cta_button_text', 'html_entity_decode');

Pricing Table Module

add_filter('dbsce_pricing_table_button_text', 'html_entity_decode');
add_filter('dbsce_pricing_table_price', 'html_entity_decode');
add_filter('dbsce_pricing_table_frequency', 'html_entity_decode');
add_filter('dbsce_pricing_table_currency', 'html_entity_decode');
add_filter('dbsce_pricing_table_subtitle', 'html_entity_decode');
add_filter('dbsce_pricing_table_title', 'html_entity_decode');

Toggle Module

add_filter('dbsce_toggle_title', 'html_entity_decode');

Enable Dynamic Content Filtering

Easily filter and decode HTML output in Divi module fields with the Divi Shortcode Enabler. Seamlessly integrate shortcodes where they're least expected and improve your page structure for a more dynamic site. Perfect for handling HTML within modules.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.