Created
September 19, 2017 09:37
-
-
Save Grawl/32070aa1546762d97863e94cc762d409 to your computer and use it in GitHub Desktop.
How to remove WooCommerce classnames from <body> and move them into WooCommerce content wrapper
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
<? | |
/* | |
Since WooCommerce CSS is a piece of shit and tries to style selectors like '.button' and 'img', it's a good idea to remove this shitty CSS. But! it's hard to implement all styles properly because WooCommerce templates is a hell on Earth without classnames consension and full of server-side rendering. So you cannot “just style it again”. You have to change almost every template function. And even you have enough time for it, there is a lot of things to change before you get a frontend that is OK. | |
So, a better idea is to remove WooCommerce classnames from your frontend root and move them to WooCommerce content root, a safe place where you want these styles. | |
*/ | |
function remove_woocommerce_body_classes() { | |
remove_filter('body_class', 'wc_body_class'); | |
} | |
add_action('init', 'remove_woocommerce_body_classes'); | |
function modify_woocommerce() { | |
add_action('woocommerce_before_main_content', function() { | |
$woocommerce_body_classes = join(' ', wc_body_class([])); | |
echo "<main class='$woocommerce_body_classes'>"; | |
}); | |
add_action('woocommerce_after_main_content', function() { | |
echo "</main>"; | |
}); | |
} | |
add_action('wp_loaded', 'modify_woocommerce'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment