I did a great amount of research and came across some solutions like this:
https://wordpress.stackexchange.com/questions/106042/force-wordpress-to-show-pages-instead-of-category
But still it isn’t exactly what I’m looking for. First of all let me explain the problem.
I made a page /blog/ and a category ‘blog’ both make use of the permalink /blog/, disabled the /category/ permalink so the SEO will be correct.
The solutions I came across didn’t match the following requirements:
- Not using 301 redirects
- Disable the /category/ use within WordPress.
- Also make it possible to only replace category when a page id uses the same slug.
I simply like to tell WordPress to display the page instead of the category.
Why don’t you just edit the category template?
Because the page I created uses Visual Composer (Post Masonry Grid) so I can’t simple move the design.
Why don’t you just use redirects?
I would like to but the permalink of the blog is the same as the page (SEO purpose.)
2
Answers
I know it’s a few years later with no solution, but I had the exact same problem you described on one site that was working in other sites. So I did some research on what was different and to help others should they run into the same issue.
Background
example.com is the domain
I have a WP page called “foobar” with content
I have a WP post category called “foobar”
I have a WP post entitled “fun things to do with foobars”, and the category is set to “foobar”
Expectations
When I go to
example.com/foobar
, I want to see the page about foobars, not a WP category page that shows all blog posts with that category.When I go to the blog post about fun things, the URL is
example.com/foobar/fun-things-to-do-with-foobars/
Setup
Here’s my setup (it does not require any additional plugins or code edits)
A couple of installed plugins are WP Rocket and Yoast on which I’ll focus in this thread.
WP Dashboard->Settings->Permalinks
Select “Custom Structure” and enter
/%category%/%postname%/
in the fieldOn the same page, change “Category base” to a single dot. “.” (no quotes, just a single dot/period/full stop
I have Yoast installed, which I had set up to override the permalink settings, but I believe this messed up my task at hand.
WP Dashboard->SEO->Advanced->Permalinks(tab)
“Change URLs->Strip the category base…” =
Keep
Then you need to clear the cache. I use WP Rocket for caching, so I flushed the cache and everything now works the way it should.
Edit: make sure you save your changes after steps 3 and 5
I know this topic is old but question is still important.
I will use blog example.
This method is code free, WP native solution. One caveat is that you cannot translate "blog" slug, so this method is only for one language if you don’t need to have different words/slugs for other languages.
/blog/%category/%postname%/
(/ trailing slash on the end is your preference)method) to remove /category from URL.
Then you will get proper URL:
/blog/yourcategory/single-post-title/
Breadcrumbs will work, all categories will be hierarchical, and
/blog
will work as page instead of category.Most importantly, when you go to your category page you will get
/blog/yourcategory
URL and it will work as archive page. When you visit single post, then also you get URL/blog/yourcategory/single-post-title/
Breadcrumbs from Yoast should work. I use Seopress Pro and breadcrumbs works like a charm (you have to go to breadcrumbs setting page and select categories for posts and posts for categories and tags if you need them).
If you do it without including
/blog
in your permalink setting it will still work, you will get page instead of category with proper url for categories, but single post will be/yourcategory/single-post-title
.