Home Forums WoodMart support forum REMOVE SIDEBAR FROM SPECIFIC CATEGORY PAGES

REMOVE SIDEBAR FROM SPECIFIC CATEGORY PAGES

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #106163

    ggeeky
    Participant

    Hi,
    I’m trying to remove the sidebar from specific category pages. What I’m looking for is a piece of code to add to my function.php that removes sidebar from category X and its subcategories.

    I’ve tried this but it doesn’t work for some reason.

    if ( !cat_is_ancestor_of ( ’93’ ) ) {
    remove_action(‘woocommerce_sidebar’, ‘woocommerce_get_sidebar’, 10);
    }

    Please advise thank you.

    #106203

    Hello,

    Add this code to the child theme in the functions.php file:

    function woodmart_disable_sidebar_on_categories() {
    	global $woodmart_options, $wp_query;
    	$ids = array(
    		40,
    		50,
    		60
    	);
    
    	if ( is_product_category() && in_array( $wp_query->get_queried_object()->term_id, $ids ) ) {
    		$woodmart_options['shop_sidebar_width'] = 0;
    	}
    }
    add_action( 'wp','woodmart_disable_sidebar_on_categories' );

    Specify the categories IDs which you want to remove the sidebar in the array

    Best Regards

    #106212

    ggeeky
    Participant

    Thank you very much.
    Is it possible to set a single category and remove the sidebar for its subcategories? cat_is_ancestor_of could work?

    #106233

    Artem Temos
    Keymaster

    Sorry, but you need to specify each category ID separately.

    #106238

    ggeeky
    Participant

    Ok fine, but the code isn’t working.

    #106271

    Artem Temos
    Keymaster

    Please, send us a screenshot where you added the code and send us a link to the page where it should work.

    #106311

    ggeeky
    Participant

    Sure.

    #106319

    ggeeky
    Participant

    Also,

    #106320

    Artem Temos
    Keymaster

    You need to edit your shop page and set Inherit value there https://prnt.sc/mhsoqd

    #106321

    ggeeky
    Participant

    It works now, thank you!!!

    #106326

    Artem Temos
    Keymaster

    You are welcome.

    #266011

    Nader
    Participant

    Hi

    Could you please help me to remove sidebar from some category pages?
    I added the code to the woodmart-child. But it doesn’t work!

    Thanks

    Attachments:
    You must be logged in to view attached files.
    #266064

    Hello,

    Unfortunately, it is not possible to remove the sidebar from some categories. Please consider the settings of the off-canvas sidebar in the Theme Settings > Shop > Sidebar and options: https://gyazo.com/11dc338a861960492f4015d75826b04c

    Best Regards

    #267111

    Nader
    Participant

    Thanks for replying
    the following code couldn’t be the answer to my question?

    function woodmart_disable_sidebar_on_categories() {
    global $woodmart_options, $wp_query;
    $ids = array(
    40,
    50,
    60
    );

    if ( is_product_category() && in_array( $wp_query->get_queried_object()->term_id, $ids ) ) {
    $woodmart_options[‘shop_sidebar_width’] = 0;
    }
    }
    add_action( ‘wp’,’woodmart_disable_sidebar_on_categories’ );

    #267240

    Hello,

    This code should work. You need to insert category IDs into the code and the code would work. If you have any questions please feel free to contact us.

    Best Regards

    #267665

    Nader
    Participant

    When I added the code to the child theme in the functions.php file, I received the below message
    There has been a critical error on this website.
    and website doesn’t work!

    Attachments:
    You must be logged in to view attached files.
    #267792

    Hello,

    Please replace the code with this one:

    function woodmart_disable_sidebar_on_categories() {
    	global $woodmart_options, $wp_query;
    	$ids = array(
    		40,
    		50,
    		60
    	);
    	if ( is_product_category() && in_array( $wp_query->get_queried_object()->term_id, $ids ) ) {
    		$woodmart_options['shop_sidebar_width'] = 0;
    	}
    }
    add_action( 'wp','woodmart_disable_sidebar_on_categories' );

    Best Regars

    #267911

    Nader
    Participant

    Same Error!

    #268069

    Hello,

    Please provide FTP access to the private area.

    Best Regards

Viewing 19 posts - 1 through 19 (of 19 total)