The Divi Theme’s many modules offer a range of opportunities for adding URLs to your page. Some examples include the button module and the image module. However these are limited to the static URL you type into the modules’ settings. What if you want to use be able to use URLs dynamically generated by shortcodes, e.g. a URL collected using the Advanced Custom Fields (ACF) plugin? Here’s how to do it.

This is a draft tip, meaning that it hasn’t been extensively tested and may not work perfectly.
It is not yet included in Divi Booster, but I hope to be able to do so in the future.

The following PHP code will search the page content for the target URLs of any button and image modules, and process any shortcodes contained within them.

add_filter('the_content', 'db_process_url_shortcodes');

function db_process_url_shortcodes($content) {
	
	$patterns = array(
		'#]*? button_url="([^"]+)"#',
		'#
]*? url="([^"]+)"#', ); foreach($patterns as $regex) { $content = preg_replace_callback($regex, 'db_process_url_shortcodes_callback', $content); } return $content; } function db_process_url_shortcodes_callback($matches) { if (isset($matches[1])) { $url = $matches[1]; // URL decode brackets $url = str_replace('%91', '[', $url); $url = str_replace('%93', ']', $url); // Do shortcodes $url = preg_replace_callback('#[[^]]*]#', 'db_process_url_shortcodes_individual', $url); return str_replace($matches[1], $url, $matches[0]); } return isset($matches[0])?$matches[0]:''; } function db_process_url_shortcodes_individual($matches) { return isset($matches[0])?do_shortcode(urldecode($matches[0])):''; }

With this code in place you should find that shortcodes are now processed within the “Button URL” field of the button module, and the “Link URL” field of the image module.

If there’s any other URL fields you’d like to see this apply to let me know.

Want get more out of Divi?

Hundreds of new features for Divi

in one easy-to-use plugin