问题
I'm using WordPress 4.9.4 running Twenty Seventeen Child Theme theme with Woocommerce Version 3.3.4. I am trying to remove the sidebar… I have tried using this:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
But haven't found the right one yet.
How do I remove all sidebars?
回答1:
The best and simple way that works with all themes is to use the get_sidebar
Wordpress action hook this way:
add_action( 'get_sidebar', 'remove_woocommerce_sidebar', 1, 1 );
function remove_woocommerce_sidebar( $name ){
if ( is_woocommerce() && empty( $name ) )
exit();
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
You might need to make some CSS changes on some html related containers
This code works on any theme as all themes use get_sidebar()
Wordpress function for sidebars (even for Woocommerce sidebar) and get_sidebar
action hook is located inside this function code.
回答2:
WooCommerce ads the side bar in code directed at this specific theme, in class WC_Twenty_Seventeen /** * Close the Twenty Seventeen wrapper. */
public static function output_content_wrapper_end() {
echo '</main>';
echo '</div>';
get_sidebar();
echo '</div>';
}
I used this code to replace that function
remove_action( 'woocommerce_after_main_content', array( 'WC_Twenty_Seventeen', 'output_content_wrapper_end' ), 10 );
add_action( 'woocommerce_after_main_content', 'custom_output_content_wrapper_end', 10 );
/** * Close the Twenty Seventeen wrapper. */
function custom_output_content_wrapper_end() {
echo '</main>';
echo '</div>';
echo '</div>';
}
来源:https://stackoverflow.com/questions/49521577/remove-woocommerce-sidebar-from-any-theme