Last active
August 20, 2020 17:55
-
-
Save robertstaddon/6933759c49d5c8842144d3adaf6320d2 to your computer and use it in GitHub Desktop.
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
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
Thanks for this! On line 18, I changed from
init
towp
and got it working. 😊