Disable sidebar on shop page but enable on product category archives

Hello, I would like to make my shop page full-width with two products per row, but enable a sidebar on left on product category archive pages. I have made the changes for the shop page via Pro’s theme options, but how can I enable the left sidebar on product category archives?

I tried to use the following code, but it adds an empty sidebar to the shop page when I don’t want one there:

/* Enable product filter sidebar on category archives */
function x_get_content_layout() {

  $content_layout = x_get_option( 'x_layout_content' );

  if ( $content_layout != 'full-width' ) {
    if ( x_is_product_category() || x_is_product_tag() ) {
      $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
      $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
    } elseif ( is_archive() ) {
      $layout = $content_layout;
    }
  } else {
    $layout = $content_layout;
  }
  if ( x_is_product_category() || x_is_product_tag() ) {
    $layout = 'content-sidebar';
  }

  return $layout;

}

Any insight into this? Thank you!

Hey @jessebrito,

Thanks for writing in!

To resolve your issue, please go to X > Theme Options > WooCommerce > Shop and set the Shop Layout to “Use Global Content Layout”. And then you will need to add this code in your child theme’s functions.php file:

// No Sidebar in Shop
// =============================================================================
function no_sidebars_allowed($contents) {
  if ( x_is_shop() ) {
    $contents = 'fullwidth';
  }
  
  return $contents;
}
add_filter('x_option_x_layout_content', 'no_sidebars_allowed');
// =============================================================================

We would love to know if this has worked for you. Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.