When is it necessary to create a DIVI Child Theme?

 

creare-plugin

Creating a child theme is a great way to add code customization to your theme without having to worry about losing those changes every time you update your main Divi theme. The procedure to create a DIVI child theme is very well described on the Elegants theme official website at the following Address.

 

Is it necessary to create a child theme if you don’t want lose the changes?

Depending on the type of change you want to make it might be enough to create a small plugin.

 

How do make a simple plugin?

Creating a simple plugin isn’t complicated. Open your favorite editor and copy the following lines of code.

<?php
/*
Plugin Name:  Disable_divi_cache
Plugin URI: https://jits.it
Description: Remove DIVI Clean cache function
Version: 1.1.1
*/

?>

Save the file, naming it with the same name we specified in the comment (plugin name), in this case Disable_divi_cache.php

Finally, now let’s add the code that this plugin will have to execute. First of all, let’s introduce a little security so that the file cannot be called up directly by adding the following line of code:

// exit if called directly
if ( ! defined( ‘ABSPATH’ ) ) exit;

So let’s add our feature which will prevent the DIVI theme from clearing the WP Rocket cache by redefining the function. As we mentioned in this POST the DIVI theme clears the cache every time something (page / product) is changed. Unfortunately, that sometimes also clears other pages that it shouldn’t, decimating our preloaded cache. Keep in mind that this small problem may no longer be present at the time you this POST. The DIVI theme is updated regularly.

if ( ! function_exists( ‘et_core_clear_wp_cache’ ) ) {
function et_core_clear_wp_cache() {
return;
}
}

 

Here is the complete code:

<?php

/*
Plugin Name:  Disable_divi_cache
Plugin URI: https://jits.it
Description: Remove DIVI Clean cache function
Version: 1.1.1
*/

// exit if accessed directlyif ( ! defined( ‘ABSPATH’ ) ) exit;
if ( ! function_exists( ‘et_core_clear_wp_cache’ ) ) {   function et_core_clear_wp_cache() { return;    } }
?>

 

at this point we just have to save the changes, zip and upload the file (give the same name) to your site by going to menu -> add new -> load plugin. Finally activate it and that’s it.

 

Enhance WP Rocket’s preload feature

With Windows server, if you have a lot of pages, I noticed that the WP Rocket cache does not completely pre-load all the pages if you have a lot of them (for example in the case of an ecommerce). You can solve this problem in the following way (for advanced users).

In the control panel of WP Rocket set the useful life of the cache to 0. In this way, WP Rocket will never clear and rebuild the cache. Then create the following php file and save it for example with the name rocket-clean-domain.php

<?php
// Load WordPress.
require( ‘wp-load.php’ );

// Preload cache.
if ( function_exists( ‘run_rocket_sitemap_preload’ ) ) {
run_rocket_sitemap_preload();
}
?>

Copy it to the server and schedule it to run. You can create a batch file and run it for example every 24 hours.

powershell “Invoke-WebRequest https://jits.it/rocket-clean-domain.php”
powershell “Invoke-WebRequest https://miosito.it/rocket-clean-domain.php”

In this way, the cache will never be cleared. The run_rocket_sitemap_preload function, due to a bug I think, will not immediately preload all cache, but within a few days your site will be fully preloaded. Keep in mind that if you make any changes you have to clear the cache of the affected pages manually. In this case have control over the whole procedure.

Obviously, any improvement comments are welcome!

 

NEWSLETTER SUBSCRIPTION



    I consent to the processing of my personal data for marketing purposes

    I accept the terms of privacy policy