1

enter image description here

How to remove the categories drop down with title "All categories" attached with the search bar seen in the image attached herewith in Magento 2 ?

We just need to show the search bar only and no category list along with.

                  <?php if($catalogsearch) : ?>
                  <div class="catalogsearch-box">
                    <span id="select-box-category"><?php echo __('All Categories') ?></span>
                    <div id="categories-box" style="display:none;">
                      <input style="display:none;" type="text" value="" id="qsearch">
                      <ul class="cat-list dd-container" id="cat">
                        <?php
                        if($depth) $depth ++;
                          $categoryFactory = $objectManager->create('Magiccart\Alothemes\Model\System\Config\CatalogSearch');
                            $categories = $categoryFactory->toOptionArray($depth);
                            echo '<li data-q="0">' . __('All Categories') . '</li>';
                            foreach ($categories as $category){
                              echo '<li data-q="'.$category['value'].'" class="' . $category['class'] . '">' . $category['label'] . '</li>';
                            }
                        ?>
                      </ul>
                    </div>                        
                  </div>

From this code, where can I set the catelogsearch as false ?

7
  • I think you are using theme. So you need to find the search section. Aug 23 '18 at 9:42
  • 2
    Your top search is modified by theme. you can find in default_head_block.xml. you will found the top search file.
    – Kevinzie
    Aug 23 '18 at 9:51
  • I have searched for this option in the admin panel everywhere. But could not find this. Let me check the default_head_block.xml file Aug 23 '18 at 9:52
  • is there any code before $catalogsearch?
    – kunj
    Aug 23 '18 at 10:37
  • $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); Aug 23 '18 at 11:02
0

Add this code into XML where you want to remove the header:

For example remove from all the page then add to default.xml

app/code/[Vendor]/[Module]/frontend/layout/default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header.container">
            <referenceBlock name="top.search" remove="true"/>
        </referenceContainer>
    </body>
</page>

Follow the below steps for the solution:

  1. Login to Admin panel
  2. Go to Catalog > Categories
  3. Select any category that you want
  4. Under Design, select the required Layout.
  5. Save configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.