My title filter appends the string length to the changed title.

  1. Why is it doing this?
  2. How can I remove it?

My goal: Change the header title only in the header section.

My filter:

function product_search_filter_the_title($title) {
if ( is_page_template( 'product-search.php' ) && $title === 'Products Search' ) {       
    return printf(__('Search Results for: %s', 'twentyseventeen'), get_product_query() );
return $title;
add_filter( 'the_title', 'product_search_filter_the_title');

What I get on my page is the following:

Search results for: "test"27

If anyone is wondering what the get_product_query() function is, it's a function to show me the requested custom query, which is not always being passed through the "s" property. Code:

function get_product_query() {

$productname_var = get_query_var('productname');
$catalog_var = get_query_var('catalog');

if (!empty($_GET['productname'])) {
    $search = $productname_var;

if (!empty($_GET['catalog'])) {
    $search = $catalog_var;

return $search;

Bonus question: Is there a way to change the title only in a specific location etc. within a specific div?

Let me know if you need any further details.

  • Well it’s coming from get_product_query(). What is that function? It’s not from WordPress, or even WooCommerce. – Jacob Peattie May 5 '18 at 9:18
  • It's my custom function. I've added it know. But I don't know how it returns the string. Also, it doesn't matter if this function is applied or not in fact. If I write a custom string within the printf request, I get the string lenght attached. Which would suggest it's because of printf - but this does not make sens :/ – theMaertin May 5 '18 at 9:39
  • Check PHP syntax first. Second, there are too much questions, third, we don't want your bonus. – Max Yudin May 7 '18 at 13:19
  • Care to elaborate what do you meant by checking the PHP syntax? Whether I am exiting too late? What is too many questions? I believe both "why" and "how" are connected to each other. And third, what group are you representing, by calling out "we"? – theMaertin May 7 '18 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.