{"id":498,"date":"2019-07-09T11:30:01","date_gmt":"2019-07-09T11:30:01","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/07\/09\/hide-empty-custom-tab-in-magento-2\/"},"modified":"2025-03-18T04:51:13","modified_gmt":"2025-03-18T04:51:13","slug":"hide-empty-custom-tab-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/hide-empty-custom-tab-in-magento-2\/","title":{"rendered":"How to Hide an Empty Custom Tab in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">According to a&nbsp;<a href=\"https:\/\/static.googleusercontent.com\/media\/research.google.com\/en\/us\/pubs\/archive\/38315.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">study by Google<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The visitors will judge the online store as beautiful or not in the only 1\/50th to 1\/20th of a second.<\/li>\n\n\n\n<li>Visually complex websites are consistently rated as less beautiful than their simpler equivalent.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A beautiful website means a visually appealing, simpler, and easy navigation website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a Magento 2 store owner, you would want to offer a shopping platform that would not confuse or irritate the shoppers! Removing unnecessary elements from the frontend is quite important as to not distract the visitors from their main goal (and obviously, ours ), i.e., making a purchase!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keeping this in mind, I have come up with a programmatic method to&nbsp;<em><strong>hide an empty custom tab in Magento 2<\/strong><\/em>. With this method, hide unnecessary tabs from the product page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a product page shows the FAQ section. However, for products with no FAQs, you\u2019d not want to show an empty FAQ tab. To hide such empty custom tabs from the storefront, implement the below method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Hide an Empty Custom Tab in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>registration.php<\/strong>&nbsp;at&nbsp;<em><strong>app\/code\/[VendorName]\/[ModuleName]<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    '[VendorName]_[ModuleName]',\n    __DIR__\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>module.xml<\/strong>&nbsp;at&nbsp;<em><strong>app\/code\/[VendorName]\/[ModuleName]<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\">\n    &lt;module name=\"[VendorName]_[ModuleName]\" setup_version=\"1.0.0\">\n        &lt;sequence>\n            &lt;module name=\"Magento_Catalog\"\/>\n        &lt;\/sequence>\n    &lt;\/module>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create\u00a0<strong>catalog_product_view.xml<\/strong>\u00a0at\u00a0<em><strong>app\/code\/[VendorName]\/[ModuleName]\/view\/frontend\/layout<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;body>\n        &lt;referenceBlock name=\"product.info.details\">\n            &lt;block class=\"Magento\\Catalog\\Block\\Product\\View\" name=\"custom.tab\" template=\"[VendorName]_[ModuleName]::product\/view\/details\/custom_tab.phtml\" group=\"detailed_info\">\n                &lt;arguments>\n                    &lt;argument translate=\"true\" name=\"title\" xsi:type=\"string\">Tab Title&lt;\/argument>\n                &lt;\/arguments>\n            &lt;\/block>\n        &lt;\/referenceBlock>\n    &lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4.   Create&nbsp;<strong>custom_tab.phtml<\/strong>&nbsp;at&nbsp; <em><strong>app\/code\/[VendorName]\/[ModuleName]\/view\/frontend\/templates\/product\/view\/details\/<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php $attributeCode = '&lt;product_attribute_code>'; ?>\n&lt;?php echo $block->getProduct()->getData($attributeCode); ?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the above steps, make your Magento 2 store presentable, simpler, and hide unnecessary custom tabs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>According to a&nbsp;study by Google A beautiful website means a visually appealing, simpler, and easy navigation website. As a Magento 2 store owner, you would&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-498","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=498"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/498\/revisions"}],"predecessor-version":[{"id":10075,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/498\/revisions\/10075"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}