When navigating to the next page of search results in Woocommerce, the title shows as
Search results: “example” – Page 2
I would like to know how I can customise this so the page number is not shown. Ideally, it would be nice to be displayed as
Search results for Example
I have looked in the files and this title seems to be called using
<?php woocommerce_page_title(); ?>
So there's not much there for me to work on.
There are lots of posts on removing the title all together, nothing on how to customise it.
You can use
woocommerce_page_title
hook to alter the title according to your need.
Here is a working code:
// define the woocommerce_page_title callback
function filter_woocommerce_page_title($page_title)
{
if (is_search())
{
$page_title = 'Search results for ' . ucfirst(get_search_query());
}
return $page_title;
}
// add the filter
add_filter('woocommerce_page_title', 'filter_woocommerce_page_title', 10, 1);
Code goes in functions.php
file of your active child theme (or theme). Or also in any plugin php files.
Hope this helps!