categories - Remove base category gives 404 error

admin2025-01-07  3

I tried to remove /category/ base from permalink structure, keeping parent category, but Wordpress gives me back 404 error page.

I'm not using any particular plugin to do that, only using . in category base and using %category%/%postname%/ as permalink structure.

If I restore /category/ base everything works fine. I have already used '/' and '.' to remove category base.

How can I solve the problem?

I tried to remove /category/ base from permalink structure, keeping parent category, but Wordpress gives me back 404 error page.

I'm not using any particular plugin to do that, only using . in category base and using %category%/%postname%/ as permalink structure.

If I restore /category/ base everything works fine. I have already used '/' and '.' to remove category base.

How can I solve the problem?

Share Improve this question edited Dec 29, 2017 at 9:44 Stefano asked Dec 28, 2017 at 21:03 StefanoStefano 1291 gold badge3 silver badges13 bronze badges 2
  • Have you seen a site that is able to do that? – Alexis Wilke Commented Dec 29, 2017 at 9:58
  • Obviously yes. I do not understand how your answer could help. – Stefano Commented Dec 29, 2017 at 10:33
Add a comment  | 

2 Answers 2

Reset to default 0

Just enter '/' OR '.' (without quotes) as the value for Category base.

Seemed to work perfectly when I tested it. I'd be interested in hearing if anyone discovers other dangers to doing this, other than the obvious potential of collisions between posts, pages, and categories.

Okay, I tested and can reproduce the problem on my test website. The Posts work as expected, but indeed, the sub-categories fail.

One solution, which is really not practical if you have a large number of categories, but resolves the issue, is to create pages with the same paths and use a Shortcode in those pages. The Shortcode will display the corresponding pages as a list. The one problem is it won't use the same formatting as expected by default in your theme...

So if you have a parent category named parent and a child category named child, you:

  1. create a page with the path set to /parent/
  2. create a child page with the path set to /child/ and then mark it as a child of /parent/

Note that you can't get the correct path for the child page (/parent/child/ in my example) without first creating the parent page. One good thing is that the look and feel of the list in the parent will thus have the same look and feel in the child.

In the pages, you can enter any text you'd like and then use a Shortcode such as this:

[display-posts category="second-category"]

I use the Display Posts Shortcode plugin, which is probably not the best plugin available for that job, but it has the advantage of work well. Feel free to try with others...

Now if you have hundred of categories and add/remove many of them all the time, that's going to be a nightmare. If you have a few well selected categories, you should be just fine that way. (You'll also need a little CSS to help the output formatting.)

There is a screenshot of the child page. We see that the path looks correct. This is because I setup the parent (right side of screen). I also show the Shortcode.

Now, what you should probably do is report that problem as a bug at WordPress.org.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257740a461.html

最新回复(0)