DIVI conditional modules display

// This filter will be fired for every Divi section, row, column and module. By the way, internally
// for Divi a section is just another module so if we talk about modules below, this also includes
// sectios, rows, and columns.
add_filter(‘et_module_shortcode_output’, ‘my_custom_et_module_shortcode_output’, 10, 3);
function my_custom_et_module_shortcode_output($output, $render_slug, $module)
// First we check whether there are any CSS classes we could check for.
// If not, we can directly return the HTML of the module and are done.
if (!isset($module->props[‘module_id’]) || et_core_is_builder_used_on_current_request() ) {
return $output;

// Now we can check if one of our two classes «user_logged_in» or «user_not_logged_in»
// are present in the CSS classes and handle them accordingly.

// If the «user_logged_in» class is present, we also check if the user is logged in.
// If both conditions are met, we return the HTML of the module and if not, we
// return an empty string and omit therefore modules HTML. If you’re curios, the ? :
// is called a ternary operator and it’s just a shortform for a simple if statement. :)
if (strpos($module->props[‘module_id’], ‘sameday-banner’) !== false) {
return is_front_page() ? $output : »;

// And here we basically do the same for the «user_not_logged_in» class but this time, we
// use the not operator (!) to check that the user is not logged in. Simple, right? ;)
//if (strpos($module->props[‘module_id’], ‘user_not_logged_in’) !== false) {
// return !is_user_logged_in() ? $output : »;

// Finally, if neither one of our classes is present in the modules CSS classes, we
// return the HTML of the module so it can be shown on the page.
return $output;