Last active
August 20, 2020 17:55
Divi - remove Divi sidebar from all WooCommerce Product pages with a hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove Divi sidebar from all WooCommerce Product pages | |
*/ | |
function mytheme_divi_output_content_wrapper_end() { | |
echo ' | |
</div> <!-- #left-area --> | |
</div> <!-- #content-area --> | |
</div> <!-- .container --> | |
</div> <!-- #main-content -->'; | |
} | |
function mytheme_remove_divi_sidebar() { | |
if ( function_exists( 'is_product' ) && is_product() ) { | |
remove_action( 'woocommerce_after_main_content', 'et_divi_output_content_wrapper_end', 10 ); | |
add_action( 'woocommerce_after_main_content', 'mytheme_divi_output_content_wrapper_end', 10 ); | |
} | |
} | |
add_action( 'init', 'mytheme_remove_divi_sidebar', 10 ); | |
/** | |
* Adjust the WooCommerce body classes for all WooCommerce Product pages | |
*/ | |
function mytheme_body_classes( $classes ) { | |
if ( function_exists( 'is_product' ) && is_product() ) { | |
$remove_classes = array('et_right_sidebar', 'et_left_sidebar', 'et_includes_sidebar'); | |
foreach( $classes as $key => $value ) { | |
if ( in_array( $value, $remove_classes ) ) unset( $classes[$key] ); | |
} | |
$classes[] = 'et_full_width_page'; | |
} | |
return $classes; | |
} | |
add_filter('body_class', 'mytheme_body_classes', 20); |
Thanks for this! On line 18, I changed from init
to wp
and got it working. 😊
Thanks for this! On line 18, I changed from
init
towp
and got it working. 😊
You bet. Cheers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Robert, I tried to use this in the latest DIVI version and although it applied the CSS, it did not hide the sidebar; the sidebar was still visible (but at the bottom of the page). Based on my testing,
if ( function_exists( 'is_product' ) && is_product() )
returns false insidefunction mytheme_remove_divi_sidebar()
. Is there another way to check if it's anis_product
page?