How to Make the Divi’s Video Module URL Fields Dynamic

by Sep 3, 2021Divi Freebies, Tutorials

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.

1

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.

  1. Go to Appearance → Theme Editor
  2. Open your child theme’s functions.phpfile
  3. Add custom PHP code
  4. Click Update File
h

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 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.