Step 1). Create the Vendor/Module/etc/frontend/event.xml in your module
<event name="controller_action_postdispatch"> <observer name="change_title_filter" instance="VendorModuleObserverFiltertitle" /> </event>
Step 2). Create the Vendor/Module/Observer/Filtertitle.php in your module
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkEventObserver;
use MagentoFrameworkViewLayoutInterface;
class Filtertitle implements ObserverInterface
{
protected $context;
public function __construct(
MagentoFrameworkViewElementTemplate $context,
MagentoFrameworkViewResultPage $resultPage,
MagentoFrameworkViewPageConfig $pageConfig
) {
$this->pageConfig = $pageConfig;
$this->resultPageFactory = $resultPage;
$this->context = $context;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
$layout = $this->context->getLayout();
$pageMainTitle = $layout->getBlock('page.main.title');
if ($pageMainTitle) {
$blockfilter = $layout->getBlock('catalog.navigation.state');
if($blockfilter){
$selectedFilters = $blockfilter->getActiveFilters();
if (!empty($selectedFilters)){
$filters = array();
foreach($selectedFilters as $filter){
$filters[] = $blockfilter->stripTags($filter->getLabel());
}
if(count($filters) > 0){
$activefilters = __("Your selection: ").implode(" - ", $filters);
$pageMainTitle->setPageTitle($activefilters);
}
}
}
}
}
}

