Override vendor\magento\module-catalog-search\view\frontend\layout\catalogsearch_result_index.xml
to your theme inside app/design/frontend/Vendor/theme/Magento_CatalogSearch/layout
and add below catalogsearch_result_index.xml in layout folder:
<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<attribute name="class" value="page-products"/>
<referenceContainer name="content">
<block class="Magento\CatalogSearch\Block\Result" name="search.result" template="Magento_CatalogSearch::result.phtml">
<block class="Magento\CatalogSearch\Block\SearchResult\ListProduct" name="search_result_list" template="Magento_CatalogSearch::product/search-list.phtml">
<arguments>
<!-- If argument's position depends on image size changeable in VDE:
positions:list-secondary,grid-secondary,list-actions,grid-actions,list-primary,grid-primary
-->
<argument name="positioned" xsi:type="string">positions:list-secondary</argument>
<argument name="viewModel" xsi:type="object">Magento\Catalog\ViewModel\Product\OptionsData</argument>
</arguments>
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
<block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName">
<argument name="name" xsi:type="string">product_list_toolbar</argument>
</action>
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="catalogsearch.product.addto" as="addto">
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
name="catalogsearch.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
<action method="setListOrders"/>
<action method="setListModes"/>
<action method="setListCollection"/>
</block>
<block class="Magento\Framework\View\Element\Template" name="search.search_terms_log" template="Magento_CatalogSearch::search_terms_log.phtml">
<arguments>
<argument name="search_terms_log" xsi:type="object">Magento\CatalogSearch\Block\SearchTermsLog</argument>
</arguments>
</block>
</referenceContainer>
</body>
Copy and rename the file app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/list.phtml
to app/design/frontend/Vendor/theme/Magento_CatalogSearch/templates/product/search-list.phtml
We have not tested it but it will work.
OR
in list.phtml try with below code :
print_r($this->getRequest()->getFullActionName());
if you get return like : catalogsearch_result_index in the search page. then add a condition for search result as below:
if($this->getRequest()->getFullActionName() == 'catalogsearch_result_index '){
// do your stuff
}