How to Make the Divi’s Video Module URL Fields Dynamic
In this tutorial, we will show you how to upgrade one of the Divi modules and add a dynamic field into it, which is not available by default.
The Divi Video module allows you to display videos on your Divi website. You can upload a video mp4 file or add YouTube URL. This tutorial will be very useful for all users who use Theme Builder templates and have a Video module added to them. By default, the video URL field is not dynamic, so we cannot use custom fields to fetch the video URL automatically. All videos must be added manually in the Video module settings.
In this tutorial, we will show you how to add a dynamic field functionality, so the video URLs can be fetched automatically from the custom post type.
The solution is quite easy. We only need to add a few lines of custom PHP code to our child theme’s functions.php file. If you don’t use a child theme yet, you can build one using our tutorial on How to Create a WordPress Child Theme for Divi or create a child theme with our free child theme generator.
Add custom code to functions.php
In this only one step, we need to add a custom PHP code to our functions.php file located in our Divi Child Theme. There are multiple ways to do that. For this tutorial, we will use WP Dashboard’s Theme Editor. You can also add a custom code by opening the file in Text/Code Editor via FTP, or File Manager available in your server dashboard.
- Go to Appearance → Theme Editor
- Open your child theme’s functions.phpfile
- Add custom PHP code
- Click Update File
PHP
// Make the Video URL field Dynamic
add_filter('et_builder_get_parent_modules', function($modules){
foreach ($modules as $module_slug => $module) {
if($module_slug === 'et_pb_video' && isset($module->fields_unprocessed)){
$module->fields_unprocessed['src']['dynamic_content'] = 'url';
$module->fields_unprocessed['src_webm']['dynamic_content'] = 'url';
}
}
return $modules;
});
This is it! We hope you enjoy reading this tutorial. Adding dynamic field support to Divi Video module might be beneficial and very useful if you are using custom post time and can save loads of time by fetching the video URL dynamically from CPT. There are more cool tutorials to come, so please make sure to sign up for our newsletter.
Jan Thielemann
Jan is the co-founder of Divi Pixel. He is a professional software developer who started developing for WordPress as a hobby. When he made his first contact with Divi in 2016, he immediately saw the potential. Shortly after he developed his first Divi plugin, which was a huge success, he started a side business selling various Divi related products. He's an expert known throughout the whole Divi developer community.
Enhance your Divi Theme with Custom Settings and New Modules. Start Creating Awesome Websites with the Divi Pixel
We offer a 14 Day Money Back Guarantee, so joining is Risk-Free!
Very cool, very practical, and easy to implement. Thanks!
Brilliant! – such a powerful and versatile function – many many thanks. After all this time, we finally a way to add dynamic content to any field….dynamic counters! – yes! I must take a look at Visibility Toggles, Classes, Colors etc. Please follow up on this if you folks get the time.
Superb. No idea why this isn’t the default for divi video modules. Thanks for sharing this snippet.
Do you have a similar snippet for adding product tags in the theme builder for products?
Hello, thank you for useful snippet.
We have a page under construction and have created a template for CPT using the Divi theme builder. Wish to be able to show dynamic video content on this template and I am trying to get this to work but the video isn’t visible on the front end. Do you have any advice for me?
/Helena
Hi Helena,
I have no idea :/ We haven’t tested it with custom CPT, but it should work.
This is great – is there a way to insert a Youtube URL as the dynamic content?
Hi Anna. I believe it’s possible if you will create a dynamic field where the link will be pulled from.
Really helpful. It worked like a magic. Thanks a lot.
Awesome guide! Works like a charm. I need to enable the Video Slider module to take URLs as dynamic content, do you know what it would take to add this? I tried duplicating the if-statement within the foreach-loop as below, (tested both “et_pb_video_slider” slug for the slider module in general, as well as the individual “et_pb_video_slider_item” module child slug). None of them worked, do you have a hint as to what I am missing?
add_filter(‘et_builder_get_parent_modules’, function($modules){
foreach ($modules as $module_slug => $module) {
if($module_slug === ‘et_pb_video’ && isset($module->fields_unprocessed)){
$module->fields_unprocessed[‘src’][‘dynamic_content’] = ‘url’;
$module->fields_unprocessed[‘src_webm’][‘dynamic_content’] = ‘url’;
}
if($module_slug === ‘et_pb_video_slider’ && isset($module->fields_unprocessed)){
$module->fields_unprocessed[‘src’][‘dynamic_content’] = ‘url’;
$module->fields_unprocessed[‘src_webm’][‘dynamic_content’] = ‘url’;
}
}
return $modules;
});
Nikolaj, have you found a solution? I am looking for the very same thing… please help 😉
Qué maravilla! muchísimas gracias!
Excellent contribution to the community! I was just looking for this. Thanks
This works perfectly! Thank you for sharing this technique. Is there an easy bit of code that you could share that would allow the Video Slider Module to have dynamic fields for the video URLs as well?
That would be very useful for portfolio projects that have multiple videos!
Thanks in advance.
Amazing!!! This work smoothly! Can you also enable the dynamic content for code module?