By default, WooCommerce adds a sidebar to your shop pages that displays product categories, filters, and other related content. However, in some cases, you may want to remove the sidebar to simplify the design or layout of your site.
To remove the WooCommerce sidebar, you can use the woocommerce_sidebar
action hook and the remove_action
function. Here’s an example code snippet:
function wpsnippets_remove_woocommerce_sidebar() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
}
add_action( 'init', 'wpsnippets_remove_woocommerce_sidebar' );
In this code snippet, we define a function wpsnippets_remove_woocommerce_sidebar
that uses the remove_action
function to remove the woocommerce_get_sidebar
function from the woocommerce_sidebar
action hook. We hook this function to the init
action, which ensures that it is loaded early enough to remove the sidebar before it is displayed.
You can modify the priority of the remove_action
function to ensure that the sidebar is removed at the appropriate time, and you can use similar code to remove other elements from the WooCommerce shop pages. Additionally, you can modify the HTML and CSS of your site to adjust the layout of the shop pages without the sidebar.