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:
/
The archive page title is:
<title>Shoes</title>
But, when I filter it (via the filtered widgets included with WooComerce).
/?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?
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/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/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?
Share Improve this question asked Dec 8, 2016 at 19:33 JeremiaJeremia 111 silver badge5 bronze badges1 Answer
Reset to default 1You 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.