Title: Hide tabs when empty
Last modified: January 23, 2019

---

# Hide tabs when empty

 *  Resolved [strozzapr](https://wordpress.org/support/users/strozzapr/)
 * (@strozzapr)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/)
 * Hi!
 * I’m looking to create a function where we would be able to hide a tab if it’s
   empty (I’ve automatically imported my products and it created a tab for every
   single one of them). However some products don’t use certain tabs yet are still
   displayed (empty).
 * Here’s one of my tabs name and ID : “Version Numérique”, ID : 2
 * Perhaps there’s also a function to only display tab when there’s content instead?
 * Thank you kindly!

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11123414)
 * Hi [@strozzapr](https://wordpress.org/support/users/strozzapr/)!
 * Some people programmatically add content to tabs so we need to allow empty tabs
   to show.
 * Here’s a function that will remove any empty tabs:
 *     ```
       // Remove Empty Tabs
       add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_tabs', 20, 1 );
   
       function yikes_woo_remove_empty_tabs( $tabs ) {
   
       	if ( ! empty( $tabs ) ) {
       		foreach ( $tabs as $title => $tab ) {
       			if ( empty( $tab['content'] ) ) {
       				unset( $tabs[ $title ] );
       			}
       		}
       	}
       	return $tabs;
       }
       ```
   
 * Cheers,
    Kevin.
 * Edit: note that this function will remove tabs when the product page is displayed.
   It won’t remove the tabs from the DB/back-end.
    -  This reply was modified 7 years, 4 months ago by [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/).
 *  Thread Starter [strozzapr](https://wordpress.org/support/users/strozzapr/)
 * (@strozzapr)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11123447)
 * Works like a charm!
 * Thank you Kevin ! 🙂
 *  [Jon](https://wordpress.org/support/users/freshyjon/)
 * (@freshyjon)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11246075)
 * That function seems to also remove the Description tab, even when there is info
   in that tab…
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11246117)
 * Hey [@freshyjon](https://wordpress.org/support/users/freshyjon/),
 * Unless the description tab’s content is being populated dynamically, I don’t 
   see how that function could be removing it. The description tab has the same `
   content` field that other tabs have and all we’re looking at is if that field
   is empty.
 * Do you know if your description tab is being populated dynamically or if there
   is any other sort of customization going on?
 *  [Jon](https://wordpress.org/support/users/freshyjon/)
 * (@freshyjon)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11246133)
 * Not sure. Pretty sure it’s using regular functionality. I’m using Divi + WooCommerce.
   As soon as I add that function, it removes the Description tab.
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11246145)
 * Hm, let’s try to explicitly keep the description tab just to see if that works.
 *     ```
       // Remove Empty Tabs
       add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_tabs', 20, 1 );
   
       function yikes_woo_remove_empty_tabs( $tabs ) {
   
       	if ( ! empty( $tabs ) ) {
       		foreach ( $tabs as $title => $tab ) {
       			if ( empty( $tab['content'] ) && strtolower( $tab['title'] ) !== 'description' ) {
       				unset( $tabs[ $title ] );
       			}
       		}
       	}
       	return $tabs;
       }
       ```
   
 *  [Jon](https://wordpress.org/support/users/freshyjon/)
 * (@freshyjon)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11246155)
 * That works!
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11246164)
 * Awesome! Not sure why the empty check is failing for you but you should be good
   with that version of the snippet.
 *  [deeoon](https://wordpress.org/support/users/deeoon/)
 * (@deeoon)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11267814)
 * Hi,
 * How can I add this function on my website ?
    I want to Hide the description tab.
   Thanks !
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11272234)
 * Hi [@deeoon](https://wordpress.org/support/users/deeoon/),
 * This is not the snippet you should use if you want to hide the description tab.
   There are dozens of other support tickets in this forum related to hiding WooCommerce’s
   default tabs. This is the snippet you want for that:
 *     ```
       // Remove Tabs.
       add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_tabs', 20, 1 );
   
       function yikes_woo_remove_tabs( $tabs ) {
   
       	// Remove the description tab.
           if ( isset( $tabs['description'] ) ) {
           	unset( $tabs['description'] );
           }
   
           return $tabs;
       }
       ```
   
 * The best place for this code is your child theme’s functions.php file. If you’re
   not using a child theme, you can use your theme’s functions.php file or a plugin
   like ​[My Custom Functions](https://wordpress.org/plugins/my-custom-functions/).
 * If you’re not familiar with adding code to your site, I think using the plugin
   is probably the best idea because it provides some safety measures.
 * All the best,
    Kevin.
 *  [xavier0623](https://wordpress.org/support/users/xavier0623/)
 * (@xavier0623)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11492190)
 * Hi, I tested your 1st code but it does’nt work, would there be an update to do
   to code?
 * thank you
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11492606)
 * Hi [@xavier0623](https://wordpress.org/support/users/xavier0623/),
 * What tab are you trying to hide?
 * Let me know.
 * Thank you,
    Kevin.
 *  [xavier0623](https://wordpress.org/support/users/xavier0623/)
 * (@xavier0623)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11492691)
 * hi, thank you for your answer, I would like to hide the woocommerce tabs if they
   are empty. I have other tabs, not generated by woocommerce, is it possible to
   hide them too?
 * if you wish we can exchange by mail this may be easier
 * my mail: [maildetestx23@gmail.com](https://wordpress.org/support/topic/hide-tabs-when-empty/maildetestx23@gmail.com?output_format=md)
 * thank you advance
    -  This reply was modified 7 years, 1 month ago by [xavier0623](https://wordpress.org/support/users/xavier0623/).
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11492809)
 * Hi [@xavier0623](https://wordpress.org/support/users/xavier0623/),
 * Which tabs are you referring to? WooCommerce won’t show their default tabs (Description,
   Additional Information) if they’re empty. Also, you can control the Reviews tab
   on a per-product (or per-site, I believe) basis.
 * Are the tabs that you’re trying to hide (that could be empty) coming from our
   plugin?
 * Let me know.
 * Thank you,
    Kevin.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Hide tabs when empty’ is closed to new replies.

 * ![](https://ps.w.org/yikes-inc-easy-custom-woocommerce-product-tabs/assets/icon-
   256x256.png?rev=1558461)
 * [Custom Product Tabs for WooCommerce](https://wordpress.org/plugins/yikes-inc-easy-custom-woocommerce-product-tabs/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yikes-inc-easy-custom-woocommerce-product-tabs/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/)
 * [Active Topics](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/reviews/)

## Tags

 * [empty](https://wordpress.org/support/topic-tag/empty/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * 14 replies
 * 5 participants
 * Last reply from: [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/hide-tabs-when-empty/#post-11492809)
 * Status: resolved