0

I want to change WooCommerce pagination links from:

  • example.com/category/page/3/ to:
  • example.com/category/3/

I found many examples of how to change '/page/' to '/something/' but I want only the number of the current page. I also tried this:

$wp_rewrite->pagination_base = ''; 

But then my url looks like this:

example.com/category//3/

And that's not good either. Is it even possible to remove 'pagination base' from url structure?

4
  • 2
    So category is a placeholder, right? How should WP know if /category/3 is page 3 or a sub-category called 3 (as that is the default URL for this case)?
    – kero
    Commented Oct 25, 2021 at 15:29
  • Kero, thank you for your reply. I see what you mean, but I know that there will be no category or subcategory named "1", "2", "3" etc. Also, if we presume that the name is the only problem, what if I have subcategory called "Page"? I get why WP add /page/ to url structure, my question is can I prevent that?
    – Milan
    Commented Oct 25, 2021 at 18:25
  • how would WP know the difference between page 3, the category with ID 3, and the category with the slug 3? The /page/ is there for a good reason to avoid these clashes. Why do you want to remove it?
    – Tom J Nowell
    Commented Oct 25, 2021 at 21:14
  • I would recommend keeping the /page/ base - it helps prevent any sort of conflicts and it's used on most websites so from a user's perspective it makes most sense. Likely better for SEO as well.
    – WPExplorer
    Commented Aug 21 at 0:57

2 Answers 2

0

If you go into the control panel, into settings and then to the "Permalink"-section, you can simply put a "." in the category-base field, which will remove any additions made to the actual URL.

Alternatively: Did you even set a custom URL-structure for your permalinks? This is obviously the first

Disclaimer: I'm not sure it works for WooCommerce.

0

My answer is, its possible, however the only way I know is to customize woocommerce files and code something almost from scratch to use url to know the page is determined by the number. However this is something hard to achieve, but possible, this because something has to tell that is the second page, and 2 or 3 or 4 is the number of the page, the result. so a variable should be in place to set that, and that variable has to have a character. Other way and maybe the best one is to pass this variable in your php session, that its invisible to the user, and you can grab the info, this customizing the wc file. That said my advice for simplicity is to change your function variable

$wp_rewrite->pagination_base = 'custom-page-pagination';

to

$wp_rewrite->pagination_base = 'pg';

and the result will be example.com/category/pg/2/

its not what is intended, but if you can live with it, woocommerce will says thanks. and who cares anyway. right! but yes its possible, but you will need to change woocommerce files code to do so. you will need to customize some wc files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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