Skip to content
Advertisement

WooCommerce: Get URL of paged shop archive

I need the link to the paged shop archive URL to add it as rel=canonical. As default WooCommerce seems to use always the URL of the “All products” page.

For example: The all product archive page has the following URL:

JavaScript

If I go to page 2, the URL is still the one from above. But the correct version would be:

JavaScript

I try to rewrite the rel=canonical tag with Yoast and want to display the current URL with /page/. So I tried this:

JavaScript

And this:

JavaScript

Unfortunately without success. It always shows only the URL of homepage (https://example.com) Is there any way to get the number of the page?

Advertisement

Answer

OK, found a solution for that. It seems that $wp->request doesn’t work on the WooCommerce shop archive.

Here’s a solution that works. But it has some hard coded URL parts in it:

JavaScript

I wonder if there is a better solution without adding /page/ to the URL.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement