We recently published this article on the Lakewood site but I know a few people will look here for Divi resources as I will continue to publish CSS tweak and modifications for Divi.
This is a very simple function that simply removed the Divi Builder Plugin scripts and styles when they aren’t being used on the current page or post. You can add the following functions to an mu-plugin or to your theme functions.php file.
Why would you want to do this you may be asking? The answer is simple, why load the Divi Page Builder assets when the page builder isn’t in use, it will just add unnecessary bloat to your page and increase your page load times.
Here is the function:
function deregister_script() { $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() ); if( !$is_page_builder_used ) { wp_dequeue_script('et-builder-modules-global-functions-script'); wp_dequeue_script('google-maps-api'); wp_dequeue_script('divi-fitvids'); wp_dequeue_script('waypoints'); wp_dequeue_script('magnific-popup'); wp_dequeue_script('hashchange'); wp_dequeue_script('salvattore'); wp_dequeue_script('easypiechart'); wp_dequeue_script('et-jquery-visible-viewport'); wp_dequeue_script('magnific-popup'); wp_dequeue_script('et-jquery-touch-mobile'); wp_dequeue_script('et-builder-modules-script'); } } add_action( 'wp_print_scripts', 'deregister_script', 100 ); function deregister_styles() { $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() ); if( !$is_page_builder_used ) { wp_dequeue_style('et-builder-modules-style'); } } add_action( 'wp_print_styles', 'deregister_styles', 100 );
Please note this is for the Divi Builder Plugin only and not for the Divi Theme. Any questions please ask them below.
Ugh. Thank you for already doing this.
Thanks, Adam. Saved me a job!
FYI, there’s an extra } in the deregister script function 😉
Thanks for pointing that out Tom! I’ve fixed it now.
Thank you, I will try it for my blog.
By the way, I have try twice in two post hit “Like” in monarch plugin, but its failed.
Thanks for letting me know, I’ll have a look into the like button.
can this be done for the DIVI theme as well?
Great article! Will this work for the DIVI theme as well?