0

I am using WooCommerce and I am trying to find a way to update the archive page default title <title></title> with the selected attribute(s) when the results are filtered.

For example:

http://example.org/product-category/shoes/

The archive page title is:

<title>Shoes</title>

But, when I filter it (via the filtered widgets included with WooComerce).

http://example.org/product-category/shoes/?filter_color=red

The archive page title still shows:

<title>Shoes</title>

What I would like it to show:

<title>Red Shoes</title>

Is this possible?

1 Answer 1

1

You will have to add the variable ?filter_color to your title tag. Something like this-

<?php
    $filter_color = $_REQUEST['filter_color'];
?>

This line of code will get the value from the URL. (Make sure this line of code runs before the HTML where you want to output it)

And then in your HTML it should look pretty much like this-

<?php
    if( $filter_color ) {
        echo '<title>'. &filter_color .' Shoes</title>';
    }

    else {
        echo '<title>Shoes</title>';
    }
?>

Here we checked weather there was a variable set for filter_color or not and adjusted the output accordingly.

1
  • Thanks so much Neit, I'm going to give this a go and see how it works :-) Is this also what you would do to echo it between a heading tag? For example: <h4>"filter name" Shoes</h4>?
    – Jeremia
    Dec 9, 2016 at 0:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.