Sidebar on Single Product Pages Only

I used the functions.php entry from this support thread but it added the sidebar to all pages, not just the single product pages. Can you please help?

This doesn’t work at all either:

Hey,

To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

Hi There,

This is the original function:

      // Get Content Layout
      // =============================================================================

      //
      // First checks if the global content layout is "full-width." If the global
      // content layout is not "full-width," (i.e. displays a sidebar) then it runs
      // through all possible pages to determine the correct layout for that template.
      //

      if ( ! function_exists( 'x_get_content_layout' ) ) :
        function x_get_content_layout() {

          $content_layout = x_get_option( 'x_layout_content' );

          if ( $content_layout != 'full-width' ) {
            if ( is_home() ) {
              $opt    = x_get_option( 'x_blog_layout' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            } elseif ( is_singular( 'post' ) ) {
              $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
              $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
            } elseif ( x_is_portfolio_item() ) {
              $layout = 'full-width';
            } elseif ( x_is_portfolio() ) {
              $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
              $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
            } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
              $layout = 'content-sidebar';
            } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
              $layout = 'sidebar-content';
            } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
              $layout = 'full-width';
            } elseif ( is_archive() ) {
              if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
                $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
                $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
              } else {
                $opt    = x_get_option( 'x_archive_layout' );
                $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
              }
            } elseif ( x_is_product() ) {
              $layout = 'full-width';
            } elseif ( x_is_bbpress() ) {
              $opt    = x_get_option( 'x_bbpress_layout_content' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            } elseif ( x_is_buddypress() ) {
              $opt    = x_get_option( 'x_buddypress_layout_content' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            } elseif ( is_404() ) {
              $layout = 'full-width';
            } else {
              $layout = $content_layout;
            }
          } else {
            $layout = $content_layout;
          }

          return $layout;

        }
      endif;

Then just look at this part:

           } elseif ( x_is_product() ) {
              $layout = 'full-width';
            }

Change full-width to either to content-sidebar or sidebar-content depending on the position of the sidebar you want.

Hope this helps.

That didnt do anything. https://www.warfighterscuba.org/store/dive-packages/15-dive-package/

// Get Content Layout
  // =============================================================================

  //
  // First checks if the global content layout is "full-width." If the global
  // content layout is not "full-width," (i.e. displays a sidebar) then it runs
  // through all possible pages to determine the correct layout for that template.
  //

  if ( ! function_exists( 'x_get_content_layout' ) ) :
    function x_get_content_layout() {

      $content_layout = x_get_option( 'x_layout_content' );

      if ( $content_layout != 'full-width' ) {
        if ( is_home() ) {
          $opt    = x_get_option( 'x_blog_layout' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } elseif ( is_singular( 'post' ) ) {
          $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
          $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
        } elseif ( x_is_portfolio_item() ) {
          $layout = 'full-width';
        } elseif ( x_is_portfolio() ) {
          $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
          $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
        } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
          $layout = 'content-sidebar';
        } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
          $layout = 'sidebar-content';
        } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
          $layout = 'full-width';
        } elseif ( is_archive() ) {
          if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
            $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } else {
            $opt    = x_get_option( 'x_archive_layout' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          }
        } elseif ( x_is_product() ) {
          $layout = 'content-sidebar';
        } elseif ( x_is_bbpress() ) {
          $opt    = x_get_option( 'x_bbpress_layout_content' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } elseif ( x_is_buddypress() ) {
          $opt    = x_get_option( 'x_buddypress_layout_content' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } elseif ( is_404() ) {
          $layout = 'full-width';
        } else {
          $layout = $content_layout;
        }
      } else {
        $layout = $content_layout;
      }

      return $layout;

    }
  endif;

Hi,

In that case, would you mind providing us your wordpress admin login in Secure Note.

Thanks

I added a secure note on my last reply.

Hi,

I went ahead and fix it by changeing the code to this.


function x_get_content_layout() {

    $content_layout = x_get_option( 'x_layout_content' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_singular( 'post' ) ) {
        $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
        $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
      } elseif ( x_is_portfolio_item() ) {
        $layout = 'full-width';
      } elseif ( x_is_portfolio() ) {
        $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
        $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
      } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
        $layout = 'content-sidebar';
      } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
        $layout = 'sidebar-content';
      } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
        $layout = 'full-width';
      } elseif ( is_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
          $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } else {
          $opt    = x_get_option( 'x_archive_layout' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        }
      } elseif ( x_is_product() ) {
        $layout = 'content-sidebar';
      } elseif ( x_is_bbpress() ) {
        $opt    = x_get_option( 'x_bbpress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
      if ( x_is_product() ) {
        $layout = 'content-sidebar';
      } 
    }

    return $layout;

}

I added this line of code in the else clause as you are using full width layout

 if ( x_is_product() ) {
        $layout = 'content-sidebar';
      } 

Hope that helps

2 Likes

Is there a way to make this pull up a custom sidebar?

Hello There,

Thanks for updating in!

Is there a way to make this pull up a custom sidebar?

  • You will need to create a custom sidebar in Appearance > Sidebars and make sure that you assign that sidebar to all your product pages. It will only appear once you have assign it. In case you haven’t assign it to a single product page, the default main sidebar will display.

Hope this helps. Kindly let us know.

Hi @RueNel,

The code worked well for bringing the main menu on the products pages. Thanks. I also am trying to customize my sidebar on product pages. So went into Appearance>Sidebars and assigned the customized sidebar to the taxonomy (Product Menu). It didn’t work. You mention assign it to all my product pages. However, in Appearance>Sidebars - pages and posts are given as option and then taxonomies but no product pages. So I created a new category of taxonomy (Product menu) and I will need to select it for every product page. But I’m waiting because I cannot get it to work on a single page yet. I selected the taxonomy (Product menu) in Sidebars to get a custom menu – and I checked off (Product menu) on one product page – yet that page is still showing up with the main menu and not my customized menu. Please advise.

@RueNel P.S. Interesting: Though it doesn’t work with taxonomies on product pages, when I choose a custom menu in Appearance>Sidebar and check of a particular page, the customized sidebar works.

@RueNel – Weirder yet, now my BLOG page has the customized menu instead of the menu default (yet I have not checked off my BLOG page on the customized menu in Appearance>Sidebar

Hi @erichomeboy,

We need to check your setup to see the issue. Please open a new thread and then share your site url and credentials using a secure note. It is not recommended to share it here because the owner of this thread can see it.

I’ll do that right now.

Thank you.
Your new thread will be responded shortly.