Magento 2 – Remove Category Filter From List Page Filters

categoryfiltermagento2product-list

How can I remove Category Filter from Magento 2 Product List Page.

Best Answer

You have to override core file into your theme, Category layered navigation comes form core file,

vendor/magento/module-layered-navigation/view/frontend/templates/layer/view.phtml

You have to get files from core and keep in your theme,

app/design/frontend/{Vendor}}/{themename}}/Magento_LayeredNavigation/templates/layer/view.phtml

Now you can set condition for this,

<?php  if($filter->getName() != __('Category')) { } ?>

in code.

<?php

/**
 * Category layered navigation
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation
 */
?>
<?php if ($block->canShowBlock()): ?>
    <div class="block filter">
        <div class="block-title filter-title">
            <strong><?php /* @escapeNotVerified */ echo __('Shop By') ?></strong>
        </div>

        <div class="block-content filter-content">
            <?php echo $block->getChildHtml('state') ?>

            <?php if ($block->getLayer()->getState()->getFilters()): ?>
                <div class="block-actions filter-actions">
                    <a href="<?php /* @escapeNotVerified */ echo $block->getClearUrl() ?>" class="action clear filter-clear"><span><?php /* @escapeNotVerified */ echo __('Clear All') ?></span></a>
                </div>
            <?php endif; ?>
            <?php $wrapOptions = false; ?>
            <?php foreach ($block->getFilters() as $filter): ?>
                <?php if (!$wrapOptions): ?>
                    <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
                    <dl class="filter-options" id="narrow-by-list">
                <?php $wrapOptions = true; endif; ?>
                <?php  if($filter->getName() != __('Category')) { ?>
                    <?php if ($filter->getItemsCount()): ?>
                        <dt role="heading" aria-level="3" class="filter-options-title"><?php echo $block->escapeHtml(__($filter->getName())) ?></dt>
                        <dd class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></dd>
                    <?php endif; ?>
                    <?php } ?>
            <?php endforeach; ?>
            <?php if ($wrapOptions): ?>
                </dl>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>