Search code examples
phpcsswordpresswoocommercestorefront

Remove "Search Results: '%s'" and blank space from Woocommerce Shop Search Results Page


I am trying to remove the "Search results: ' ' " text that shows above products on the Woocommerce Storefront search results page. Below is an image with the referenced text circled:

enter image description here

I have tried looking under search.php in the theme editor, but could only find how to remove the "Search results for '%s'" from the breadcrumb. How would I remove only what is circled in the image above?

Edit:

I have used the following code to remove the search results title, but a blank space is left where the title was removed. How would I also remove this blank space?

function filter_woocommerce_page_title($page_title){
  if (is_search()){
    {$page_title = '';
  }
}

add_filter('woocommerce_page_title', 'filter_woocommerce_page_title', 10, 1);

Solution

  • You need to use the woocommerce_page_title hook. If is_search() is true then you remove the text:

    do_action( 'woocommerce_page_title',
        function( $page_title ) {
            if ( is_search() ) {
                $page_title = ''; // Or your custom text
            }
            return $page_title;
        },
        10, 1
    ); 
    

    See the Hooks Reference for more info.

    For hiding the margin that will remain, try setting the following CSS:

    .search .woocommerce-products-header__title {display: none;}