I am trying to create a SILO structure on one of my WordPress site.
I have always checked this option on Yoast SEO plugin “Strip the category base (usually /category/) from the category URL.”
So my category pages have this URL: sitename.com/apple/ (where “apple” is the category page)
Now I want to create a new “page” with the same slug, apple.
I can create a new “apple” page easily, however, when I go to sitename.com/apple/ the category page is displayed — instead of the newly created page.
My question: Is there a way to “override” the default priority of category over a page? I’d like to show page because I will have control over it — I can customize, add more content, and change them easily (plus, pages are going to help me structure my site better)
Appreciate your help!
One possible solution is to not change the category base and leave as-is, but instead modify any output of a category link to strip the category base via a filter. This of course will result in a 404 if you haven’t created a page in place of where these links point, so creating a page for every category is required.
You’ll probably want to test this thoroughly for any side-effects, use at your own risk!
EDIT – altering just top level category links:
I created the following, fairly simple function in order to make the pages a higher importance than categories when loading the content.
(Note: this may not the best, but a simple way. I found an issue, when using the Advanced Custom Fields plugin, it doesn’t insert the custom fields neither of the old, nor of the new page by default. Adding
get_queried_object()->ID
as the ACFget_field()
‘s second parameter solved this. Test it carefully in your WP environment.)You can include it in your theme’s functions.php. This looks to work OK with the Yoast SEO plugin.
There is a super simple and perfectly working answer here:
https://stackoverflow.com/questions/32310453/make-wordpress-use-the-page-instead-of-category
For the sack of completeness:
Background
category is set to “foobar”
Expectations
foobars, not a WP category page that shows all blog posts with that
category.
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 field
On 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
Depends. If you’re trying to set 2 different page with the same URL it’s not a good idea. But if you do not care about category pages you can redirect them to your pages.
This code goes in
.htaccess
and redirect /category/page to /page/The “WordPress way” to do this would be to create a custom php template for your category page, and apply your customizations there, rather than by creating a unique “Page.”
There are also numerous plugins available that allow you to add images and other custom fields to the category archive page, which may be a better option if you would rather not modify theme files.
Alternatively, I’d suggest adding a category base that is perhaps one of your primary target keywords
First strip the category in yoast
No-index the category in yoast but before doing that the permalink structure should be set as
/%category%/%postname%/
Sorry but y don’t have enought reputation for comment in @bencergazda answer.
I find this the best solution. But i had a error with the image show in header theme, because don´t get the correct post-id.
For solution i’ll add the text line in the code:
“global $post; $post->ID = $matchingPage->ID;”
The result
Best regards