Skip to content

Instantly share code, notes, and snippets.

@xlawok
Created May 10, 2021 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlawok/5d5bcb43e41ee48a704579e1cade1a23 to your computer and use it in GitHub Desktop.
Save xlawok/5d5bcb43e41ee48a704579e1cade1a23 to your computer and use it in GitHub Desktop.
Woocommerce paged category and tags canonical
<?php
if(is_paged()&&is_product_category()) {
$thisCat = get_query_var('product_cat');
$category_link = get_term_link($thisCat, 'product_cat');
echo '<link rel="canonical" href="' . $category_link . '" />';
}
if(is_paged()&&is_product_tag()) {
$thisTag = get_query_var('product_tag');
$tag_link = get_term_link($thisTag, 'product_tag');
echo '<link rel="canonical" href="' . $tag_link . '" />';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment