最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

WooCommerce: How to insert filtered attribute(s) in page title of archive?

programmeradmin1浏览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:

/

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论