            <div class="sidebar main-sidebar" role="complementary" itemscope="itemscope" itemtype="http://schema.org/WPSideBar">
            <?php if (is_singular()) {
		if(function_exists('is_bbpress') && is_bbpress()) {
		    $custom_sidebar = mom_option('bbpress_right_sidebar');
    		    if(function_exists('is_buddypress') && is_buddypress()) {
			$custom_sidebar = get_post_meta(get_queried_object_id(), 'mom_right_sidebar', TRUE);
			if ($custom_sidebar == '') {
			      $custom_sidebar = mom_option('buddypress_right_sidebar');
			}
		    }
		    
		    if (!empty($custom_sidebar)) {
			dynamic_sidebar($custom_sidebar);		    
		    } else {
			dynamic_sidebar( 'right-sidebar' );
		    }
		} elseif(function_exists('is_buddypress') && is_buddypress()) {
		   $custom_sidebar = get_post_meta(get_queried_object_id(), 'mom_right_sidebar', TRUE);
		   if ($custom_sidebar == '') {
		    $custom_sidebar = mom_option('buddypress_right_sidebar');
		   }
		    if (!empty($custom_sidebar)) {
			dynamic_sidebar($custom_sidebar);		    
		    } else {
			dynamic_sidebar( 'right-sidebar' );
		    }
		} elseif (function_exists('is_product') && is_product()) {

		    	$custom_sidebar = get_post_meta(get_the_ID(), 'mom_right_sidebar', true);
		    	if ($custom_sidebar == '') {
		        	$custom_sidebar = mom_option('wc_product_right_sidebar');
		    	}

			    if (!empty($custom_sidebar)) {
				dynamic_sidebar($custom_sidebar);		    
			    } else {
				dynamic_sidebar( 'right-sidebar' );
			    }
			}  else {
		    global $post;
		    $custom_sidebar = get_post_meta(get_queried_object_id(), 'mom_right_sidebar', TRUE);
		    if (is_single()) {
		    if (mom_option('cat_sidebar_in_posts') == 1) {
					if ($custom_sidebar == '') {
						global $post; 
						$parent_cat = get_the_category($post->ID);
						$parent_cat = $parent_cat[0]->cat_ID;
						$cat_data = get_option("category_".$parent_cat);
						$custom_sidebar = isset($cat_data['sidebar']) ? $cat_data['sidebar'] :'';
				    }
			}

		    if ($custom_sidebar == '') {
			    $custom_sidebar = mom_option('post_right_sidebar');
			}
		    }
		    if (!empty($custom_sidebar)) {
			dynamic_sidebar($custom_sidebar);		    
		    } else {
			dynamic_sidebar( 'right-sidebar' );
		    }
		}
	    } elseif (is_category()){
		$cat_data = get_option("category_".get_query_var('cat'));
		$custom_sidebar = isset($cat_data['sidebar']) ? $cat_data['sidebar'] :'';
		if ($custom_sidebar == '') {
		    $custom_sidebar = mom_option('cat_sidebar');
		}
		if (!empty($custom_sidebar)) {
		    dynamic_sidebar($custom_sidebar);		    
		} else {
		    dynamic_sidebar( 'right-sidebar' );
		}
	    }  elseif (is_author()){
		    $custom_sidebar = mom_option('author_sidebar');
		if (!empty($custom_sidebar)) {
		    dynamic_sidebar($custom_sidebar);		    
		} else {
		    dynamic_sidebar( 'right-sidebar' );
		}
	    } elseif(function_exists('is_bbpress') && is_bbpress()) {
		    $custom_sidebar = mom_option('bbpress_right_sidebar');
		    if (!empty($custom_sidebar)) {
			dynamic_sidebar($custom_sidebar);		    
		    } else {
			dynamic_sidebar( 'right-sidebar' );
		    }
		} elseif(function_exists('is_buddypress') && is_buddypress()) {
		    $custom_sidebar = mom_option('buddypress_right_sidebar');
		    if (!empty($custom_sidebar)) {
			dynamic_sidebar($custom_sidebar);		    
		    } else {
			dynamic_sidebar( 'right-sidebar' );
		    }
		} elseif(function_exists('is_woocommerce') && is_woocommerce()) {
		  $woo_page_id = '';
		  if (is_shop()) {
		      $woo_page_id = get_option('woocommerce_shop_page_id');
		  } elseif (is_cart()) {
		      $woo_page_id = get_option('woocommerce_cart_page_id');
		  } elseif (is_checkout()) {
		      $woo_page_id = get_option('woocommerce_checkout_page_id');
		  } elseif (is_account_page()) {
		      $woo_page_id = get_option('woocommerce_myaccount_page_id');
		  } else {
		      $woo_page_id = get_option('woocommerce_shop_page_id');
		  }
		  $custom_sidebar = get_post_meta($woo_page_id, 'mom_right_sidebar', TRUE);
		    if (!empty($custom_sidebar)) {
			dynamic_sidebar($custom_sidebar);		    
		    } else {
			dynamic_sidebar( 'right-sidebar' );
		    }
	    } else {
		if ( is_active_sidebar( 'right-sidebar' ) ) {
		    dynamic_sidebar( 'right-sidebar' );
		}
	    } ?>

           </div> <!--main sidebar-->
            <div class="clear"></div>          