Home › Forums › WoodMart support forum › REMOVE SIDEBAR FROM SPECIFIC CATEGORY PAGES
REMOVE SIDEBAR FROM SPECIFIC CATEGORY PAGES
- This topic has 18 replies, 4 voices, and was last updated 4 years, 5 months ago by
Elise Noromit.
-
AuthorPosts
-
February 6, 2019 at 12:41 pm #106163
ggeekyParticipantHi,
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.
February 6, 2019 at 3:46 pm #106203
Elise NoromitMemberHello,
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
February 6, 2019 at 4:38 pm #106212
ggeekyParticipantThank you very much.
Is it possible to set a single category and remove the sidebar for its subcategories? cat_is_ancestor_of could work?February 6, 2019 at 9:29 pm #106233
Artem TemosKeymasterSorry, but you need to specify each category ID separately.
February 6, 2019 at 9:49 pm #106238
ggeekyParticipantOk fine, but the code isn’t working.
February 7, 2019 at 7:02 am #106271
Artem TemosKeymasterPlease, send us a screenshot where you added the code and send us a link to the page where it should work.
February 7, 2019 at 9:00 am #106311
ggeekyParticipantSure.
February 7, 2019 at 9:15 am #106319
ggeekyParticipantAlso,
February 7, 2019 at 9:23 am #106320
Artem TemosKeymasterYou need to edit your shop page and set Inherit value there https://prnt.sc/mhsoqd
February 7, 2019 at 9:27 am #106321
ggeekyParticipantIt works now, thank you!!!
February 7, 2019 at 9:39 am #106326
Artem TemosKeymasterYou are welcome.
February 12, 2021 at 9:02 pm #266011
NaderParticipantHi
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.February 13, 2021 at 12:18 am #266064
Elise NoromitMemberHello,
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
February 16, 2021 at 6:31 pm #267111
NaderParticipantThanks 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’ );February 17, 2021 at 8:59 am #267240
Elise NoromitMemberHello,
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
February 18, 2021 at 7:05 pm #267665
NaderParticipantWhen 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.February 19, 2021 at 9:16 am #267792
Elise NoromitMemberHello,
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
February 19, 2021 at 5:21 pm #267911
NaderParticipantSame Error!
February 20, 2021 at 5:00 pm #268069
Elise NoromitMemberHello,
Please provide FTP access to the private area.
Best Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register