Last updated on September 13, 2023

Remove WooCommerce Sidebar

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Remove the WooCommerce sidebar.

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.

Last updated on September 13, 2023. Originally posted on May 9, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *